How do I fix a 502 bad gateway error combined with a 302 Nginx connection refused error?

Posted March 10, 2021 135 views

My hosted node app stopped working with a 502 Bad Gateway Error and I noticed 302 connection errors when I typed in sudo tail -30 /var/log/nginx/error.log

api = the subdomain I’ve put the node app on

2021/03/10 21:01:44 [error] 283085#283085: *302 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET /favicon.ico HTTP/1.1", upstream: "", host: "", referrer: ""

sudo nginx -t returned saying that my nginx configuration is ok

this is the file in nginx/sites-available (api is standing in for the subdomain I’ve put the node app on):

location / {
proxy_pass http://localhost:3001;
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/; # managed by Certb>
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Cer>
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


This didn’t start happening until yesterday. Could someone help me figure out what’s gone wrong, please?

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,

As far as I can see from the error, the backend service that is supposed to be running on port 3001 is not active.

You need to make sure that you start the service so that Nginx could connect to that backend service.

You can take a look at this answer here for more information: