Big websites rarely serve pages from a single machine. Your request first reaches a gateway, such as a load balancer, CDN or reverse proxy, which passes it to the server that builds the page. A 502 Bad Gateway means the gateway got an invalid response, or none at all, from that server.
In almost every case the problem is on the website's side, and it often clears within minutes.
What you can do as a visitor
- Wait a minute and reload. 502s often appear while a site restarts or deploys an update.
- Check whether it's down for everyone with our website checker, or look up the service in our list of status pages.
- Clear your cache or try Incognito mode in case your browser saved the error page.
- Try another browser, device or network. Rarely, a VPN or proxy in the middle causes a 502.
If the 502 continues on every device, the website has an outage and there's nothing more you can do except wait.
If you run the website
- Check that your application server (for example PHP-FPM, Node.js, Gunicorn or Puma) is running and hasn't crashed or run out of memory.
- Read the proxy's error log (Nginx:
error.log), which usually names the failing upstream. - Make sure the proxy points at the right host and port, and that a firewall isn't blocking it.
- Look for responses that are too large or malformed, and for workers being killed by timeouts.
- If you use a CDN such as Cloudflare, check whether the error page is branded by the CDN (problem reaching your server) or by your own server.
Common causes, explained simply
Think of the gateway as a receptionist passing your request to someone in the back office. A 502 happens when the receptionist gets nonsense back, or nobody answers the internal phone at all. In practice that's usually one of these:
- The application crashed or is restarting. During a deployment, servers are briefly taken out of service; if traffic reaches one too early, the gateway returns 502.
- The server ran out of memory and the operating system killed the process that builds pages.
- A misconfigured proxy points to the wrong port, or uses HTTPS when the server expects HTTP.
- Network trouble inside the data centre between the load balancer and the servers behind it.
Who shows the 502 page tells you a lot
Look at the error page. If it carries a CDN's branding, such as Cloudflare's grey diagram with "Bad gateway" highlighted between the host and your browser, the CDN is working and the website's own server is the problem. A plain "502 Bad Gateway" with "nginx" underneath comes from the website's own proxy. Either way, the fault is with the site, not with you. Large services such as Discord, Reddit or ChatGPT show 502s for a few minutes during busy periods or incidents; you can check their live status on our site before trying any fixes at home.
Questions
Is a 502 Bad Gateway my fault?
Almost never. It's a server-side error between the website's own systems. Reloading or waiting is usually all you can do.
How long does a 502 error last?
Most clear within a few minutes, during a restart or deployment. If it lasts longer, the website is having an outage.
What's the difference between 502, 503 and 504?
502: the gateway got a bad response from the server behind it. 503: the server is temporarily unavailable, often overloaded or in maintenance. 504: the server behind the gateway took too long to respond.
Can my router cause a 502 Bad Gateway?
Almost never. The error is sent by a server on the website's side. The rare exception is a proxy, VPN or company firewall in the middle of your connection.
Should I keep refreshing a 502 page?
Refresh once after a minute. Rapid refreshing adds load to a struggling site and won't make it recover faster.