【发布时间】:2018-11-04 14:50:54
【问题描述】:
我已经为 https 设置了letsencrypt,并且在没有 www 时可以正常工作。出于某种原因,我只能让“example.com”与 https 一起正常工作(即重定向到https://example.com),但是当我转到“www.example.com”时,它不会直接转到 https,只有在我刷新它这样做的页面。这是我的 nginx 默认配置:
server {
listen 80;
server_name www.example.com example.com;
return 301 https://$host$request_uri;
}
server {
# listen 80 default_server;
# listen [::]:80 default_server;
listen 443 ssl;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
}
我在 conf 中尝试了各种重定向,但似乎都没有工作。所以 https 似乎在工作,但只有在页面刷新之后。任何帮助将不胜感激,谢谢。
【问题讨论】: