ERR_TOO_MANY_REDIRECTS

August 20, 2019 141 views
Let's Encrypt Nginx

I’m trying to configure the https protocol on my website, but i have that error in browser:

ERR_TOO_MANY_REDIRECTS

This is my /etc/nginx/sites-available/default file:

server {
    listen [::]:80;
    return 301 https://$host$request_uri;
}

server {

    listen [::]:443;
    server_name domukasi.pl www.domukasi.pl;

    location / {

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:3000;
      proxy_read_timeout  90;

      proxy_redirect      http://127.0.0.1:3000 https://domukasi.pl;
    }
  }

Can you help me?

1 Answer
ageorgiev August 20, 2019
Accepted Answer

Hello,

I had a similar issue and I’ve needed to add proxysetheader X-Forwarded-Proto https to my nginx conf in order to sort it.

Try adding the following line in your nginx conf.
Also you can always check the syntax of the nginx conf by using this command:

nginx -t

This will show you if you have any syntax errors in the configuration files.

proxy_set_header X-Forwarded-Proto https;

Let me know how it goes
Alex

  • I add your line to default file and i have a same error in browser, now my code look like this:

    server {
        listen [::]:80;
        return 301 https://$host$request_uri;
    }
    
    server {
    
        listen [::]:443;
        server_name domukasi.pl www.domukasi.pl;
    
        location / {
    
          proxy_set_header        Host $host;
          proxy_set_header        X-Real-IP $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header        X-Forwarded-Proto $scheme;
          proxy_set_header X-Forwarded-Proto https;
    
          # Fix the “It appears that your reverse proxy set up is broken" error.
          proxy_pass          http://127.0.0.1:3000;
          proxy_read_timeout  90;
    
          proxy_redirect      http://127.0.0.1:3000 https://domukasi.pl;
        }
      }
    

    I checked my syntax, and everything is okay. Is there any other way to get rid of this error?

    I also checked a listening on ports 80 and 443, here are the results
    sudo lsof -i :80

    
    COMMAND   PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
    nginx    6346     root    6u  IPv6 15423161      0t0  TCP *:http (LISTEN)
    nginx    6348 www-data    6u  IPv6 15423161      0t0  TCP *:http (LISTEN)
    nginx   12503     root    6u  IPv4   468507      0t0  TCP *:http (LISTEN)
    nginx   12548 www-data    6u  IPv4   468507      0t0  TCP *:http (LISTEN)
    

    sudo lsof -i :444

    COMMAND   PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
    nginx    6346     root    7u  IPv6 15423162      0t0  TCP *:https (LISTEN)
    nginx    6348 www-data    7u  IPv6 15423162      0t0  TCP *:https (LISTEN)
    nginx   12503     root    7u  IPv4   468508      0t0  TCP *:https (LISTEN)
    nginx   12548 www-data    7u  IPv4   468508      0t0  TCP *:https (LISTEN)
    

    sudo netstat -ltnp | grep -w ’:80’

    tcp6       0      0 :::80                   :::*                    LISTEN  
    

    sudo netstat -ltnp | grep -w ’:443’

    tcp6       0      0 :::443                  :::*                   LISTEN  
    
    edited by MattIPv4
Have another answer? Share your knowledge.