[英]www to non www redirect is not working for https on nginx
我正在尝试将所有网址重定向到example.com,而不是www.example.com。 当我键入www.example.com
并按Enter键将其重定向到https://domain.com时,它可以按预期工作。 但是,当我键入https://www.example.com时,它将转到https://www.example.com,但我尝试将其重定向到https://example.com。 我遵循了一些类似问题的解决方案,但是没有用。 以下是我的nginx配置文件。
upstream puma {
server unix:///home/deploy/apps/myprod/shared/tmp/sockets/myprod-puma.sock;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
#listen 80 default_server deferred;
#listen 80;
listen 443 default ssl;
server_name domain.com;
ssl_certificate /etc/nginx/ssl/domain.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/domain.key;
root /home/deploy/apps/myprod/current/public;
access_log /home/deploy/apps/myprod/current/log/nginx.access.log;
error_log /home/deploy/apps/myprod/current/log/nginx.error.log info;
#location ^~ /assets/ {
#gzip_static on;
#expires max;
#add_header Cache-Control public;
#}
location ^~ /(assets|fonts|swfs|images)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
}
请可以告诉别人我应该进行哪些更改以实现此非www重定向
尝试使用此server
阻止代码:
server {
listen 80;
listen 443;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.