[英]NGINX Redirect HTTPS to HTTP getting Cert Error
I have the following NGINX configuration to redirect https to http and then run 301 redirects. 我有以下NGINX配置将https重定向到http,然后运行301重定向。 The problem is, if people are visiting https://domain.com
instead of being redirected they are stuck on a certificate error page. 问题是,如果人们访问的是https://domain.com
而不是被重定向,则他们将停留在证书错误页面上。
server {
listen 443;
server_name domain.com www.domain.com;
rewrite ^(.*) http://$host$1 permanent;
}
server {
listen 80;
server_name domain.com www.domain.com;
location ~ /assets/img/images/(.*)$ {
return 301 https://domain.xyz/images/legacy/$1;
}
location ~ /frame/(.*)$ {
return 301 https://domain.xyz/embeded/$1;
}
}
It is a bit of a chicken-and-egg problem such that there is no real way to say that you don't support TLS/SSL without first supporting TLS/SSL. 这有点棘手的问题,因此没有真正的方法可以说您不首先支持TLS / SSL就不支持TLS / SSL。
So, in order to service the redirect, you still must serve a valid certificate. 因此,为了服务重定向,您仍然必须提供有效的证书。
Once you obtain a certificate (for example a free one from Let's Encrypt ), you just add this to your first server
block: 获得证书后(例如,从Let's Encrypt获得免费证书),只需将其添加到第一个server
块中:
listen 443 ssl;
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/private.key;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.