当我访问 www.example.com 上的页面时,我会看到“欢迎使用 nginx”屏幕。如果我输入https://www.example.com但 http 或 www 不起作用,example.com 也不起作用。
从台式电脑上我没有遇到任何问题。
这是我的配置:
server {
listen 80;
server_name example.com;
error_log /var/log/nginx/error.log;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl; # managed by Certbot
server_name www.example.com;
#access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
include proxy_params;
#proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 90;
proxy_pass http://xx.xxx.xx.xxx:8001;
}
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias path/static/;
}
location /media/ {
alias path/media/;
}
ssl_certificate path/fullchain.pem; # managed by Certbot
ssl_certificate_key path/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam path/ssl-dhparams.pem; # managed by Certbot
if ($host = 'example.com') {
return 301 https://www.example.com$request_uri;
}
#I commented this out because the page stoped working with "too many redirects"
#if ($host = 'www.example.com') {
# return 301 https://www.example.com$request_uri;
#}
if ($scheme != "https") {
return 301 https://www.example.com$request_uri;
} # managed by Certbot
}
答案1
您没有匹配的服务器块,http://www.example.com
因此nginx
将使用默认服务器块。许多安装将默认服务器块放在名为的文件中,default
该文件显示“欢迎使用 Nginx”页面。
最简单的解决方法是通过将语句更改为以下内容来允许example.com
并www.example.com
匹配您的第一个server
块server_name
:
server_name example.com www.example.com;
看这个文件了解更多信息。