502 Bad Gateway error for my server running Node JS on nginx proxy

I am getting 502 bad gateway error: when I check the nginx error log, I find this:

2017/05/06 02:36:04 [error] 48176 # 0: * 135 connect () failed (111: connection refused) while connecting to upstream, client: 10.163.XX.X, server: abc-def - ghi, request: "GET / favicon.ico HTTP / 1.1", upstream: " https://127.0.0.1:5300/favicon.ico ", host: "hostnname", referrer: "hostname-1

I've searched internet enough but couldn't find anything. It's worth noting here that this intermittent error only arrives on a specific page.

Could this be a code issue? or nginx setup problem> Can anyone help me here.

Some of my nginx conf:

  upstream node_api_server {
    server localhost:5300 fail_timeout=0;
  }

location / {
    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 X-NginX-Proxy true;
    proxy_read_timeout 5m;
    proxy_connect_timeout 5m;
    proxy_pass_header Set-Cookie;

    proxy_pass https://node_api_server;
    proxy_redirect off;
    proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;
    break;
}

      

+3


source to share


3 answers


502 errors are usually caused by NGINX not being able to pass the request "upstream", in which case your Node.js server (which is also indicated by the error message: "Connection refused").



It might crash and restart, so check its log files to see what is causing the crashes.

+2


source


Make sure you are using npm start

either the script that launches the application.



0


source


We got 502 because the path doesn't have the correct case in the call request, in this case it's the filename. The code runs locally (in VS Code), but not when deployed.

const repoName = require ('../data/reponame'); // This should be repoName

-1


source







All Articles