NGINX:将非www https重定向到https://www [英] NGINX: redirect non-www https to https://www
本文介绍了NGINX:将非www https重定向到https://www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了这个答案 https://stackoverflow.com/a/28068250/3108268 ,但它仅从http重定向到https而不是www到www,但是如果我访问我的网站 https://example.com ,我会看到您的连接不安全".
I followed this answer https://stackoverflow.com/a/28068250/3108268 but it redirects only from http to https and non www to www, but if I go to my website at https://example.com I get 'your connection is insecure'.
如何将其重定向到 https://www ?
server{
listen 443 ssl;
server_name www.mydomain.com;
root /www/mydomain.com/;
ssl on;
ssl_certificate /ssl/domain.crt;
ssl_certificate /ssl/domain.key;
.
.
.
}
server{
listen 80;
server_name www.mydomain.com mydomain.com;
return 301 https://$server_name$request_uri;
}
server{
listen 443;
server_name mydomain.com;
return 301 https://www.$server_name$request_uri;
}
推荐答案
第三台服务器缺少SSL证书,这就是浏览器表示连接不安全的原因.
the third server is missing SSL certificates which is why the browser is saying the connection is insecure.
将最后两台服务器替换为:
replace your last two servers with:
# redirect www.mydomain.com to https
server {
listen 80;
server_name www.mydomain.com;
return 301 https://$server_name$request_uri;
}
# redirect mydomain.com to https
server{
listen 80;
server_name mydomain.com;
return 301 https://www.$server_name$request_uri;
}
这篇关于NGINX:将非www https重定向到https://www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!