Troubleshooting
What does 502 Bad Gateway mean?
Short answer
A 502 response means a gateway or proxy received an invalid response from an upstream server. Find which component returned it, then inspect its connection to the upstream and the matching application logs. The status alone does not identify the root cause.
What changes the answer
- Which proxy generated the response
- Upstream process, socket and port
- Recent deployments and matching log timestamps
Locate the gateway first
A visitor can see a 502 from a CDN, a load balancer or a reverse proxy on the application server. Those components do not have identical upstream paths. Identify the layer producing the response before editing the application's web-server configuration.
Record the failing hostname, path and time. Compare a working request with the failure. If an intermediary provides a request identifier, use it to correlate logs without sharing session cookies, authorization headers or other private request data.
Check whether the upstream can respond
On the affected service, inspect whether the upstream process is running and listening on the expected port or socket. A deployment may change a listening address while the proxy still points at the old one. A worker may exit during a request, or a socket may have permissions that prevent the proxy from reaching it.
These are areas to investigate, not conclusions that follow from the status code. Match the proxy's error entry with the application or process-manager log. If the upstream is healthy locally but the gateway fails, compare the actual network path and configuration used by the gateway.
Do not begin by increasing every timeout
Connection establishment and waiting for a response are different stages. Nginx exposes separate controls for those stages. A timeout adjustment cannot repair an incorrect upstream address or a process that is no longer running.
A 504 is the separate gateway-timeout status. Keep the distinction when interpreting a failure, while allowing for application-specific logging and intermediaries that provide limited detail. Investigate the recorded error before treating either response as a request for more server resources.
Make the smallest reversible change
Back up the affected configuration, inspect it for syntax errors and limit any reload to the intended service. Avoid restarting unrelated websites on a shared server. After a change, repeat the original request and inspect the new log entry rather than relying on a successful home-page load alone.
If the error remains, retain the evidence and escalate with the hostname, time, request identifier and sanitized logs. Do not send credentials or full environment files to a support ticket. The troubleshooting checklist links the observed response to sensible next checks without claiming to diagnose a server it has not inspected.