A 502 Bad Gateway error means one server, acting as a middleman, asked another server for your page and got back a broken or empty reply. It usually points to a busy or crashed server, a bad CDN setting, or a timed-out request — not your computer. Most 502s clear on their own within minutes.
You loaded your website (or someone else's) and instead of the page you got a short message: 502 Bad Gateway. Sometimes the page also shows the name of the web server software or a cloud provider's branded error screen. Nothing you clicked caused it, and refreshing may or may not help.
This guide is for beginners and small business owners who just want their site back. The good news: a 502 is almost always fixable, and often it fixes itself. It is one of a family of server errors — the "5xx" codes that mean something went wrong on the server side, not with your browser. We will find out what is causing yours and clear it step by step.
Start with two quick questions. First, is the site down for everyone, or just you? Paste the address into a free "is it down right now" checker, or ask a friend on a different network to open it. If it loads fine for them, the problem is on your side — your browser, connection, or local DNS cache. If it is down for everyone, the problem is on the server or the layer in front of it.
Second, does turning off the CDN change anything? A CDN (Content Delivery Network) is a network of servers that sits in front of your site to speed it up and shield it. Services like Cloudflare are CDNs. If you temporarily pause the CDN and the site loads, the proxy layer was the culprit. If it still 502s, the origin server itself is the problem.
Modern websites rarely run on a single machine. Your request usually passes through a gateway — a server that receives your request and forwards it to another server for the real work. A gateway is like a receptionist who takes your question and walks it to the right department.
The server that does the real work is the upstream server — the "department" further back that generates the actual page. On a typical hosting stack, a web server such as Nginx acts as the gateway and passes the request to an upstream application server (for example, PHP running your WordPress site).
A 502 Bad Gateway happens when the gateway forwards your request but gets back an answer it cannot understand — an empty reply, a dropped connection, or garbage instead of a proper page. The gateway is working, so it does not stay silent; it reports "the server behind me gave me a bad answer." That message is the 502.
The most common reasons the upstream reply goes bad are: (1) the origin server is overloaded or briefly down, so it cannot answer in time; (2) PHP-FPM crashed or the request timed out — PHP-FPM (FastCGI Process Manager) is the service that runs your PHP code, and if it dies or takes too long, the gateway gets nothing usable; (3) a faulty CDN or reverse-proxy configuration, such as a wrong Cloudflare setting; (4) a firewall or security rule blocking the request between the two servers; (5) a DNS problem pointing traffic to the wrong or unreachable place; or (6) a plugin or theme causing a long-running request that never finishes before the timeout.
Work from the outside in — easiest and most likely first, deeper server checks last. Here is the order and who each check helps.
| If the 502 is… | Likely cause | What to try |
|---|---|---|
| Gone after a refresh | A brief server hiccup | Nothing — it was temporary |
| Only on your device | Browser cache or local DNS | Clear cache, flush DNS, try another network |
| Gone when CDN is off | CDN/proxy misconfiguration | Review Cloudflare/CDN settings |
| On some pages only | Slow plugin/theme or PHP timeout | Deactivate plugins, raise PHP timeouts |
| Across the whole server | Host-side outage or overload | Contact your hosting provider |
A 502 and its cousins overlap, so it helps to know the neighbours. A 500 Internal Server Error means the server hit a code-level fault; the 503 and 504 errors mean the server is unavailable or the upstream took too long to answer. If your symptom does not match a 502, those guides may fit better.
Ctrl+R (Windows) or Cmd+R (Mac).Ctrl+Shift+R (Windows) / Cmd+Shift+R (Mac).ipconfig /flushdns; on macOS run sudo dscacheutil -flushcache. Then reload the site.upstream, timeout, or PHP-FPM around the time of the error — they point straight at the failing piece.max_execution_time and max_input_time so requests finish before the gateway gives up. See our PHP settings guide for exactly where to change these safely.The three mistakes that waste the most time with a 502 are:
You cannot stop every hiccup, but you can make 502s rare. Three habits do most of the work.
Finally, keep a recent backup on hand. It will not prevent a 502, but it turns any future troubleshooting into a low-risk task.
It means one server passed your request to another server and got back a broken or empty reply. The first server is a middleman (a gateway); the second does the real work (the upstream server). "Bad Gateway" is the middleman's way of saying "the server behind me gave me a bad answer."
Usually not directly. A 502 is generated on the server side, not by your browser. It can be caused by your own site's plugins or PHP timeouts if you run the site, but as a visitor there is nothing you did to trigger it. Your only job is to rule out your device, then wait or report it.
Yes. Cloudflare is a CDN and proxy that sits in front of your site, so it can return a 502 when it cannot get a good reply from your origin server — or when a Cloudflare setting is misconfigured. Temporarily pausing Cloudflare (or setting records to "DNS only") tells you whether the proxy layer is the cause.
Rarely. Most 502s are temporary and clear within minutes as the overloaded or restarting server recovers. A 502 that keeps returning points to an ongoing cause — a crashing service, a bad proxy setting, or an under-resourced server — which is fixable once you find it using the steps above.
Check whether it is site-wide and persistent. If every site on the server is down, or the 502 keeps coming back with no change from you and the error log mentions upstream or PHP-FPM failures, it is a host-side issue. Contact your hosting provider with the error time and log lines so they can investigate.
Both involve a gateway and an upstream server. A 502 means the upstream sent back an invalid reply; a 504 means the upstream sent back no reply in time (a timeout). Our 503 and 504 guide covers timeouts in detail.
A 502 Bad Gateway is a server-side message: a gateway server got an invalid reply from the upstream server behind it. Start by refreshing and ruling out your own device, then check whether the CDN or your site's plugins and PHP timeouts are to blame. If the whole server keeps returning 502s, it is a host-side problem worth reporting. Most of the time you will be back online within minutes.
Next step: before you make any server-side change, set up a reliable safety net with our guide to backing up and restoring your website — so every fix you try is easy to undo.
The editorial team behind the Bitrich777 Hosting Help Center — practical, tested guides on web hosting, WordPress, servers, DNS, SSL, email, security and migration. Every walkthrough is reproduced on a live host before it is published.
View all guides by the Hosting Team Spotted an error? Tell us