我一直在寻找将我的网站从 www.domain.com 重定向到 domain.com
我关注了这个Nginx no-www to www and www to no-www
但是对于正常的http://www.domain.com它正在重定向到domain.com
但是当我尝试 https://www.domain.com它保持原样,不会重定向到 https://domain.com
我不知道我错过了什么
server {
listen 80;
server_name www.domain.com;
// $scheme will get the http protocol
// and 301 is best practice for tablet, phone, desktop and seo
return 301 $scheme://domain.com$request_uri;
}
server {
listen 80;
server_name domain.com;
// here goes the rest of your config file
// example
location / {
rewrite ^/cp/login?$ /cp/login.php last;
// etc etc...
}
}
最佳答案
您需要设置另一台服务器来监听 https 并重定向它
server {
listen 443 ssl;
server_name www.example.com;
# add ssl config to avoid certificate warning
return 301 https://example.com;
}
您可以在一台服务器中将 http 和 https 重定向相加
server {
listen 80 443;
server_name www.example.com;
ssl on;
# ssl config
return 301 $scheme://example.com;
}
关于ruby-on-rails - nginx url 从 www 重定向到 https 的无 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21938178/