mydomain.com重定向了太多次 ERR_TOO_MANY_REDIRECTS

分享于 

4分钟阅读

ubuntu

  繁體

问题:

我在Ubuntu 16.04上尝试使用let's Encrypt保护Nginx。

获取SSL证书之前的mydomain.conf文件


server {


 server_name mydomain.com www.mydomian.com ;


 # Tell Nginx and Passenger where your app's 'public' directory is


 root /var/www/backup/mycode/public;


 # Turn on Passenger


 passenger_enabled on;


 rails_env development;


 passenger_ruby /usr/local/rvm/gems/ruby-2.5.6/wrappers/ruby;



}



http://mydomain.com/工作正常。

我尝试通过以下方法获取SSL证书


sudo certbot --nginx -d mydomain.com -d www.mydomain.com



结果是


Your existing certificate has been successfully renewed, and the new certificate


has been installed.



The new certificate covers the following domains: https://mydomain.com and


https://www.mydomain.com



获取SSL证书之后的mydomain.conf文件


server {


 server_name mydomain.com www.mydomain.com ;


 # Tell Nginx and Passenger where your app's 'public' directory is


 root /var/www/backup/mydomain.com/public;


 # Turn on Passenger


 passenger_enabled on;


 rails_env development;


 passenger_ruby /usr/local/rvm/gems/ruby-2.5.6/wrappers/ruby;



 listen 443 ssl; # managed by Certbot


 ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot


 ssl_certificate_key /etc/letsencrypt/live/mydomain.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.mydomain.com) {


 return 301 https://$host$request_uri;


 } # managed by Certbot



 if ($host = mydomain.com) {


 return 301 https://$host$request_uri;


 } # managed by Certbot



 server_name mydomain.com www.mydomain.com ;


 listen 80;


 return 404; # managed by Certbot



}



http://mydomain.com/重定向到https://mydomain.com/太多次


mydomain.com redirected you too many times.


ERR_TOO_MANY_REDIRECTS



为什么它重定向太多次?

第二个服务器块的用途是什么?


server {


if ($host = www.mydomain.com) {


 return 301 https://$host$request_uri;


} # managed by Certbot



if ($host = mydomain.com) {


 return 301 https://$host$request_uri;


} # managed by Certbot



server_name mydomain.com www.mydomain.com ;


listen 80;


return 404; # managed by Certbot



 }



答案1:

你可以试试这个:

How to Fix Err too many Redirects

这个解决方案是针对wordpress.com的,但可以修复你的问题。

希望这可以帮到你。


答案2:

这个块导致问题


server {


 if ($host = www.mydomain.com) {


 return 301 https://$host$request_uri;


 } # managed by Certbot



 if ($host = mydomain.com) {


 return 301 https://$host$request_uri;


 } # managed by Certbot



 server_name mydomain.com www.mydomain.com ;


 listen 80;


 return 404; # managed by Certbot



}



此服务器块将用户重定向到https,但是,它还会将https重定向到https,这会导致问题,你可以将它更改为:


server {


 listen 80;


 server_name mydomain.com www.mydomain.com;


 return 301 https://mydomain.com$request_uri;


}





COM  时间  RED  Redirect  
相关文章