【发布时间】:2015-05-09 22:11:39
【问题描述】:
我正在尝试让我的网站仅使用 HTTPS。我已经查看了整个 stackoverflow 并尝试了该站点的 nginx 设置文件的许多建议设置,但我仍然无法让所有地址组合正常工作。我需要在文件中进行哪些更改才能使其正常工作?
这两个地址组合不会重定向 -
- http://www.example.com > 无重定向(错误输出)
- https://example.com > 无重定向(错误输出)
这是设置文件的样子 -
server {
listen [::]:80;
server_name www.example.com;
return 301 https://$host$request_uri;
}
server {
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen [::]:443 default_server ipv6only=off;
server_name example.com www.example.com;
# rest of config file...
}
【问题讨论】:
-
用 $server_name 替换 $host 变量。应该工作!