toolfree

502 Bad Gateway

What a 502 means, how it differs from 503 and 504, and what to check when your own server returns one.

Runs in your browser

Click a code to copy it.

5xx · Server error

The request was fine. The server failed to handle it.

CodeMeaning
Internal Server ErrorSomething broke and the server has nothing more specific to say.
Not ImplementedThe server does not support what was asked of it at all.
Bad GatewayA proxy asked something upstream and got an answer it could not use.The upstream answered badly. 504 means it did not answer in time, and 503 means this server chose not to try.
Service UnavailableTemporarily refusing to serve — overloaded or in maintenance.
Gateway TimeoutA proxy waited for something upstream and gave up.

Something in the middle got a bad answer

A 502 comes from a machine that is not the one meant to answer you. A proxy, load balancer or CDN passed your request upstream, got a reply back, and could not make sense of it.

So a 502 is never really about the server you asked. It is about the conversation between two servers behind it — which is why it is so often invisible from the outside and obvious in the logs.

502, 503 and 504 are three different failures

CodeWhat happened
502The upstream answered badly — malformed, or the connection dropped mid-reply
503This server chose not to try — overloaded, or in maintenance
504The upstream did not answer in time

Getting these right in your own services matters more than it seems: a 503 with a Retry-After header tells a client exactly when to come back, where a 502 tells it nothing useful.

If you are seeing one on someone else’s site

There is very little you can do, and it is almost never your end. Refresh after a minute. If it persists across networks and devices, it is theirs.

Worth ruling out once: a stale cached redirect or a corporate proxy of your own can produce a 502 that nobody else sees.

If your own server is returning one

The usual causes, roughly in order:

The application log is nearly always more informative than the proxy log here. The proxy only knows that the answer was unusable; the application knows why.