5xx Server Error
Safe to retry
502 Bad Gateway
A proxy or gateway got an invalid response — or no response — from the server behind it.
What causes it
- The upstream application crashed or is not listening on the expected port or socket.
- The upstream returned a malformed response, or closed the connection early.
- A deploy in progress: the old process stopped before the new one was ready.
- A container health check failing so the load balancer has no healthy targets.
How to fix it
- Check whether the upstream process is running and bound to the address the proxy expects (`ss -ltnp`).
- Read the proxy error log — nginx logs the exact upstream address and failure reason.
- For zero-downtime deploys, start the new process and confirm it is healthy before stopping the old one.
At a glance
- Class
- 5xx Server Error
- Reference
- RFC 9110 §15.6.3
- Standardised
- Yes
- Retry the request?
- Yes, with backoff
Other 5xx server error codes
- 500 Internal Server Error
- 501 Not Implemented
- 503 Service Unavailable
- 504 Gateway Timeout
- 505 HTTP Version Not Supported
- 506 Variant Also Negotiates
- 507 Insufficient Storage
- 508 Loop Detected
- 510 Not Extended
- 511 Network Authentication Required
- 520 Web Server Returned an Unknown Error
- 521 Web Server Is Down
- 522 Connection Timed Out
- 523 Origin Is Unreachable
- 524 A Timeout Occurred
- 525 SSL Handshake Failed
- 526 Invalid SSL Certificate