Question

Multiple node apps nginx https error

Posted April 28, 2021 130 views
NginxNode.jsConfiguration Management

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 ERRTOOMANY_REDIRECTS. What should I change in my configuration?

Thanks in advance

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

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