Question

Multiple node apps nginx https error

I’ve configured two nodejs apps and launched them using pm2.

  • domain.link - running on port 8080
  • auth.domain.link - running on port 3000

I’ve configured nginx for domain.link and everything is working fine.

server {

root /var/www/html;
index index.html index.htm index.nginx-debian.html;

server_name domain.link www.domain.link;

location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
}

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


    if ($host = domain.link) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;

    server_name domain.link www.domain.link;
    return 404; # managed by Certbot

}

The second app I’ve configured very similar:

server {

root /var/www/html;
index index.html index.htm index.nginx-debian.html;

server_name auth.domain.link www.auth.domain.link;

location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
}

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


        if ($host = auth.domain.link) {
            return 301 https://$host$request_uri;
        } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name auth.domain.link www.auth.domain.link;
        return 404; # managed by Certbot

}

Unfortunately, when I go to auth.domain.link, I’ve got an error ERR_TOO_MANY_REDIRECTS. What should I change in my configuration?

Thanks in advance


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

Are you using Auth0 for your auth subdomain? If so you need to define app.set("trust proxy", 1); in your application.

Let me know how it goes! Regards, Bobby