title: 502 Bad Gateway error for my server running with Node JS on nginx proxy
body: <p>I am getting 502 bad gateway error: when I check the nginx error log I find this:</p>
  
  <blockquote>
    <p>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: "<a href="https://127.0.0.1:5300/favicon.ico" rel="noreferrer">https://127.0.0.1:5300/favicon.ico</a>", host: "hostnname", referrer: "hostname-1</p>
  </blockquote>
  
  <p>I searched internet enough but could not find anything. One thing to note here is that, this intermittent error is coming only on a particular page.</p>
  
  <p>Could this be a code issue? or nginx configuration issue> Can anyone please help me here.</p>
  
  <p>Some of my nginx conf:</p>
  
  <pre><code>  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;
  }
  </code></pre>