Score:0

Nginx works with IP address but not URL for home page, gives too many redirections error

ir flag

I have spent the last 2 days going over a lot of questions like this but I can't seem to understand what I am doing wrong or if for some reason my case is just different.

So yes I know this is a common question but I feel I have exhausted all other options before posting this question.

I have a site "mysite.duckdns.org" fake site, but it is good for the point of this explanation.

I also have a data keeping site " data.mysite.duckdns.org" I am using Duck DNS a free DNS service if that makes a difference, I don't see why it would though.

My problem is when I load a page besides my home page everything works, say "mysite.duckdns.org/contact" that loads fine.

When I load the site with the public IP address the page loads fine to the home page say 111.111.111.111 ( again not the real public IP but it works when I enter the correct one )

But when I try and just enter in the site URL "mysite.duckdns.org" I get an error when my browser says there are too many redirects.

I have a feeling it has to do with when I convert from http to https but I have tryed all the combinations of www / http / https that I can and I still come up with the same error.

I have tried flushing my DNS as well.

Any pointers would be of great help as I am slowly going crazy here looking at the same code.

My data site works fine, redirects to HTTPS and works with the correct URL I gave it.

My nginx site site-avalibale code is as follows :

'''
server {

        root /var/www/mysite.duckdns.org;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name mysite.duckdns.org www.mysite.duckdns.org;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location /grafana/ {
                proxy_pass http://localhost:3000;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.duckdns.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysite.duckdns.org/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 = mysite.duckdns.org) {
        return 301 https://$host$request_uri;
    }
        listen 80 default_server;
        listen [::]:80 default_server;

        server_name mysite.duckdns.org;

    return 404; # managed by Certbot
}

My data site has the following Nginx Config file :

    server {

        root /var/www/data.mysite.duckdns.org;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name data.mysite.duckdns.org www.data.mysite.duckdns.org;

        location / {
                proxy_pass http://localhost:8086;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/data.mysite.duckdns.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/data.mysite.duckdns.org/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 = data.mysite.duckdns.org) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80;

        server_name data.mysite.duckdns.org;
    return 404; # managed by Certbot


}
server {
    if ($host = data.mysite.duckdns.org) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



        server_name www.data.mysite.duckdns.org;
    listen 80;
    return 404; # managed by Certbot


}
Lex Li avatar
vn flag
If you check the output of `curl mysite.duckdns.org`, you can see which URL the web server wants to redirect. Then `curl` on that URL and see what's the next URL. If such troubleshooting cannot reveal the culprit to you, edit the question to include the results so that others can comment further.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.