[英]nginx redirect httP://WWW.example to httPS://example (SSL/HTTPS and to NON-WWW)
I am trying to get 我试图得到
http://www.domain
https://www.domain
http:// domain
https:// domain
to all redirect to 4. https://domain
全部重定向到
https://domain
3 and 4 both end up at 4. 3和4都以4结尾。
1 and 2 - do not end up at 4. 1和2-不以4结尾。
I also tried to do the www to non-www redirect using an s3 bucket and cloudfront, but unfortunately, this causes certificate issues. 我还尝试使用s3存储桶和Cloudfront将www重定向到非www,但不幸的是,这会导致证书问题。
Here is what I currently have in my nginx config: 这是我当前在nginx配置中拥有的:
server {
listen 80;
server_name www.{{ nginx_server_name }} {{ nginx_server_name }};
return 301 https://{{ nginx_server_name }}$request_uri;
}
server {
listen 443;
server_name www.{{ nginx_server_name }}
ssl on;
charset utf-8;
ssl_certificate {{ certbot_output_dir }}/{{ letsencrypt_cert_filename }};
ssl_certificate_key {{ certbot_output_dir }}/{{ letsencrypt_privkey_filename }};
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-..........
ssl_prefer_server_ciphers on;
return 301 https://{{ nginx_server_name }}$request_uri;
}
server {
listen 443;
server_name {{ nginx_server_name }};
ssl on;
charset utf-8;
ssl_certificate {{ certbot_output_dir }}/{{ letsencrypt_cert_filename }};
ssl_certificate_key {{ certbot_output_dir }}/{{ letsencrypt_privkey_filename }};
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-..........
ssl_prefer_server_ciphers on;
You config seems correct, but are those parameters? 您的配置似乎正确,但是这些参数是吗? Maybe this works for you:
也许这对您有用:
server {
listen 80;
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
This will forward all the http requests to www.example.com and example.com to https://example.com you should then also create a listener on https with host name www.example.com to forward the same way. 这会将所有http请求转发到www.example.com和example.com到https://example.com ,然后您还应该在https上以主机名www.example.com创建一个侦听器,以进行相同的转发。 So not using the parameters, or was that because of obfuscation?
所以不使用参数,还是因为混淆?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.