Question

Too many redirect with Nginx and subdomain

Posted August 22, 2021 97 views
NginxDigitalOcean DropletsStrapi

Hi!
I’m completely new to Nginx and followed DigitalOcean’s tutorial on how to set it up with LetsEncrypt! I must have done something wrong though because I am getting a ERR_TOO_MANY_REDIRECTS message when navigating to the site.
Not sure if it makes a difference, but the redirect is for a subdomain (strapi.mysite.com). There is no config for the root domain mysite.com yet.

I have the following config in /etc/nginx/sites-available/mysite.com:

server {
    # Listen HTTP
    server_name strapi.mysite.com;


    location / {
        proxy_pass http://strapi;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $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 Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }

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


    listen 80;
    server_name strapi.mysite.com;
    return 404; # managed by Certbot


}

I’m not quite sure what I did wrong here. I do not see an obvious loop, but perhaps it’s my inexperience with Nginx. Any ideas?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

You question doesn’t offer much info and context. But looking at the conf details above, all looks good to me, at least from Nginx side.

Not sure what other settings you might have done elsewhere.

Perhaps this answer can offer a bit more help
https://www.digitalocean.com/community/questions/nginx-too-many-redirects