0

I am getting a "too many redirect error" when I try to go to my own websites. Those websites are hosted on my server with Nginx inside a Letsencrypt Docker(Docker Hub: https://hub.docker.com/r/linuxserver/letsencrypt/). It is redirecting to the same url, e.g. https://example.com/ -> https://example.com/

Here are my configs:

server {
    listen 443 ssl;
    server_name site1.com;
    return 301 https://www.site1.com$request_uri;
}

server {
    listen 443 ssl;

    root /www/site1_com/www/public_html;
    index index.php index.html;

    server_name www.site1.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

-

server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

-

server {
    listen 443 ssl;

    root /config/www/site2.com/public_html;
    index index.php;

    server_name site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

server {
    listen 443 ssl;

    root /config/www/site2.com/img;
    index index.php;

    server_name img.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

}

server {
    listen 443 ssl;

    root /config/www/site2.com/upload;
    index index.php;

    server_name upload.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;



    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

-

server {
    listen 443 ssl;

    server_name cloud.site4.me;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        proxy_max_temp_file_size 2048m;
        proxy_pass https://10.0.0.254:443;
    }
}

p.s. there are multiple sites hosted on that Nginx instance, which some of them works and some don't

Updated Configs:

Site1(working):

server {
    listen 443 ssl;
    server_name site1.net;
    return 301 https://www.site1.net$request_uri;
}

server {
    listen 443 ssl;

    root /config/www/site1.net/www/public_html;
    index index.php index.html;

    server_name www.site1.net;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

site2(not working, testing with the root of the working site):

server {
    listen 443 ssl;

    root /config/www/site1.net/www/public_html;
    index index.php index.html;

    server_name www.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}
  • can you share a config of one of the sites that is experiencing the issue? – SteamerJ Dec 7 '18 at 16:23
  • 1
    The first config in my post is the one that experiencing the issue, though, I have another site with the exact same config(except the "server_name" and the "root" path) does not experience this issue. I have tried to change the root path as well. – TheBlueKingLP Dec 7 '18 at 16:29
  • Could it be the site code that is doing the redirect? You can use fiddler to see the redirect chain and if it's hopping from example.com -> www.example.com -> example.com endlessly it might be in code. You can further confirm that by changing the redirect in nginx from a 301 to a 307 if all the redirect requests are currently 301. Remember if you do that to use a different browser, clear cache or use incognito since 301 redirects are cached in the browser. – SteamerJ Dec 7 '18 at 16:35
  • I tried all your suggestions just now, and none of them fixed my issue, I tried to point the root of the site that is having issue to the root of the site that is working fine, still not working,I did clear cache and tried to use another browser on another device. – TheBlueKingLP Dec 7 '18 at 16:45
  • can you please share the updated config? Also, have you tried having fiddler running when you hit the site to see what the redirect behavior looks like? – SteamerJ Dec 7 '18 at 16:48

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.