Skip to content

5xx Server error

502 Bad Gateway

A proxy or gateway got an invalid response from the server behind it.

What 502 means

Your request reached a proxy, load balancer or CDN (nginx, Cloudflare, AWS ALB), but the application server behind it crashed, refused the connection or returned garbage.

Common causes

  • The app server crashed, is restarting, or isn't listening on the expected port.
  • A deploy in progress.
  • The upstream response was malformed or too large.

How to fix it

If you're calling an API

  • Retry with backoff; 502s are often brief, during deploys or restarts.
  • Check the provider's status page.

If you run the server

  • Check the app is running and the proxy points at the right host and port; read the proxy's error log.

Should you retry?

Yes, with backoff.

Example response

HTTP
HTTP/1.1 502 Bad Gateway
Content-Type: application/problem+json

{
  "type": "about:blank",
  "title": "Bad Gateway",
  "status": 502,
  "detail": "A proxy or gateway got an invalid response from the server behind it."
}

Defined in: RFC 9110 (HTTP Semantics). 502 is a server error: the problem is on the server's side.

Debugging an API call? Convert your request with the cURL converter, check the response with the JSON formatter, or see whether the API is down on its status page.

Often confused with

HTTP 502 FAQ

What does HTTP 502 mean?

502 Bad Gateway: A proxy or gateway got an invalid response from the server behind it. Your request reached a proxy, load balancer or CDN (nginx, Cloudflare, AWS ALB), but the application server behind it crashed, refused the connection or returned garbage.

Is 502 a client or server error?

It's a server error (5xx): the server failed to handle a valid request, so the fix is usually on the server's side.

How do I fix a 502 error?

Retry with backoff; 502s are often brief, during deploys or restarts. Check the provider's status page.

Should I retry after a 502?

Yes, with backoff.

Other 5xx status codes

All HTTP status codes