mydomain.com将您重定向了太多次。 ERR_TOO_MANY_REDIRECTS

我试图在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/ is working fine.

我尝试通过以下方式获取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/ is redirecting to https://mydomain.com/ too many times

mydomain.com redirected you too many times.
ERR_TOO_MANY_REDIRECTS
  1. Why is it redirecting too many times?

  2. what is the purpose of the second server block?

    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 make all redirects to https://www.dogoodcars.com/ ?
评论