简体   繁体   中英

502 Bad Gateway on reverse proxy nodejs using Nginx with https

I've seen similar questions like this asked a lot but the errors they're getting don't seem to be a 502 bad gateway just an issue with setting up the server.

So I'm running a nodejs application using pm2 to keep the process running.

In my nginx /sites-available/default file I have...

server {

    listen 80;
    listen [::]:80 default_server;

}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

        ssl     on;
        ssl_certificate /etc/letsencrypt/live/server.name.comfullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/server.name.com/privkey.pem;

    root /var/www/html;

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

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        #proxy_pass https://0.0.0.0:4444;
            #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;
    }

        location /demo {
            proxy_pass https://0.0.0.0:4444;
            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;
        }

}

So I've got my certificate setup and I can hit my server on https and see everything i've placed in the index.html file. Within the index.html file there's a <a href="https://server.name.com/demo">Link</a> that forwards me to /demo where in my location block I'm trying to proxy the port 4444 which my application is running on.

I'm getting a 502 Bad Gateway error when I hit the page.

I'm a bit lost on the steps to debug this. Any help?

Is on 0.0.0.0:4444 realy a https service running and not http? Anyway i would recommend not to use ssl behind the reverese-proxy because of performance issues and there is no need for encryption.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM