我按照这个答案https://stackoverflow.com/a/28068250/3108268进行操作,但它仅从http重定向到https,而非www重定向到www,但是如果我访问https://example.com进入我的网站,则会收到“您的连接不安全”的信息.
如何将其重定向到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证书,这就是浏览器表示连接不安全的原因.
原文链接:https://www.f2er.com/nginx/532350.html将您的最后两台服务器替换为:
# 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;
}