我正在使用nginx托管一个网站,并使用certbot为www.website.com
创建了一个HTTPS证书。以下是当前配置:
server {
root /var/www/website/html;
index index.html index.htm index.nginx-debian.html;
server_name website www.website.com website.com;
location / {
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.website.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.website.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.website.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name website www.website.com website.com;
return 404; # managed by Certbot
}
这适用于从www.website.com
到https://www.website.com
的重定向。但是,当我尝试连接到website.com
时,我得到了404错误。
我想知道如何正确设置重定向,使website.com
重定向到https://www.website.com
。
1条答案
按热度按时间xdyibdwo1#
通过使用
rewrite
设法解决了这个问题:另外,当我重新启动nginx时,我注意到一些关于
nginx.service
启动的警告:我从配置文件的
server_name
变量中删除了website.com
,重新启动,警告消失了。