What a 502 Bad Gateway error means
Most websites sit behind another server: a proxy, a load balancer or a content delivery network. A 502 means that front server asked the one behind it for your page and got a broken answer, or none.
Common causes
- The application behind the proxy has crashed or is not running.
- The application is restarting after an update, and requests arrive in the gap.
- The proxy is pointed at the wrong port or address after a configuration change.
- The application closes connections early because it is out of memory or overloaded.
- A firewall between the two servers is blocking them from talking.
What to check first
- Is the application process running? Restart it and watch whether it stays up.
- Read the proxy's error log. It usually names the exact address it failed to reach.
- Think about what changed last: a deployment, a new setting, a server move.
- If you use a content delivery network, check its status page and whether your own server answers when you bypass it.
502, 503 or 504?
All three mean the visitor did nothing wrong. A 502 is a bad answer from the server behind, a 503 means the server cannot take requests right now, and a 504 means the server behind took too long.
Know when it happens
A 502 during a restart can last seconds and go unnoticed. One that lasts is an outage. KeenCrow checks every minute and emails you when three checks in a row fail, with the status code it saw.