502 Bad Gateway

Free

An upstream server returned an invalid response.

What it means

From a proxy or load balancer when the origin is unreachable or spoke nonsense. If you are seeing this on your own deployment, the application process is usually not listening on the port the proxy expects.

Class
5xx Server error
Defined in
RFC 9110 §15.6.3
Cached by default
No

When you receive a 502

  • A proxy, load balancer or CDN reached the origin server and got nothing valid back. The origin is the thing to look at.
  • It is often brief, during a deploy or a restart; retry after a moment.
  • Persistent 502s behind a cloud load balancer often mean the app's keep-alive timeout is shorter than the balancer's idle timeout.

When you send a 502

  • Your proxy sends it, not your application.
  • Check the app is running and listening where the proxy points. Inside a container, binding to 127.0.0.1 instead of 0.0.0.0 is the classic cause.
  • Read the proxy's error log - it names the upstream failure: connection refused, reset, or an invalid header.

On the wire

HTTP/1.1 502 Bad Gateway
Server: nginx
Content-Type: text/html

<html><body><h1>502 Bad Gateway</h1></body></html>

Often confused with