5xx Server errors
HTTP 502 Bad Gateway
HTTP 502 Bad Gateway means a proxy or load balancer got an invalid response, or no response, from the server behind it.
What 502 Bad Gateway means
A 502 comes from the layer in front of your app (nginx, Cloudflare, a cloud load balancer), not from your code. The upstream Node process crashed, was restarting, closed the connection early, or is listening on a different port.
Common causes
- The Node.js process crashed or is restarting during a deploy.
- nginx proxy_pass points to the wrong port or container name.
- Keep-alive mismatch: the app closes idle sockets before the proxy does.
How to fix or use it
Check the app logs and that the process is listening where the proxy expects. Set Node server.keepAliveTimeout higher than the proxy's upstream keep-alive, and use rolling or zero-downtime deploys.
Express (Node.js) example
const server = app.listen(3000);
// Outlive nginx's upstream keep-alive (60 s) so it never reuses a closed socket
server.keepAliveTimeout = 65_000;
server.headersTimeout = 66_000;SEO impact
Same as 500 for crawlers: short spikes are retried, long outages lead to lost rankings.
