我有一个Debian9VM和nginx作为我的web服务器,并在我的配置中有以下内容。
server {
listen 80;
server_name www.example.com;
return 301 https://$host$request_uri;
}现在,如果我导航到example.com或www.example.com,它将重定向到https://www.example.com。
但是,如果我在地址框中输入以下内容或类似的内容:example.com/site/about,它会尝试重定向到https://example.com/site/about (没有www),Chrome和Firefox会警告我该站点没有该链接的证书。
我正在使用CertBot。它的服务器配置包含:
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;如何让example.com/site/about重定向到https://www.example.com/site/about。
我相信一开始,我有一个if条件和一个正则表达式,但我在nginx网站上看到了简化https重定向的提示,并使用了上面的代码。
发布于 2019-05-12 05:25:47
您可以使用nginx服务器的以下变体:
server {
listen 80;
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
}它使用www检索https url。另外,如果你可以访问你的域名服务器,你可以做CNAME记录,将no-www重定向到www。
https://stackoverflow.com/questions/56093088
复制相似问题