
You open your website and instead of your homepage you see a plain white page: “502 Bad Gateway”. Your site was working fine an hour ago, and now every visitor is locked out. A 502 bad gateway error is one of the most common website errors, and the good news is that it is usually temporary — and often fixable in minutes once you know where to look.
This guide explains what a 502 Bad Gateway error means, what causes it, and how to fix it — whether your site runs on WordPress, sits behind Cloudflare, or lives on a VPS. We also cover the lookalike 503 and 504 errors, so you can fix the right problem.
What Is a 502 Bad Gateway Error?
A 502 Bad Gateway error means one server received an invalid response from another server it was trying to reach. Your web server (Nginx or Apache) acts as a gateway, passing each request to the application behind it — PHP-FPM, a Node app, or an upstream server. When that backend crashes or answers with garbage, the gateway has nothing valid to show your visitor, so it returns HTTP status code 502.
Unlike a 404, which means a page does not exist, a 502 is a server-side problem. Your content is usually still there; the server simply cannot reach it right now. That is why a 502 often appears suddenly after a deploy or a plugin update — and why it sometimes vanishes on its own.
502 vs 503 vs 504: What Is the Difference?
These three errors look alike but point at different faults:
- 502 Bad Gateway: the backend is not answering properly — it crashed, restarted, or sent an invalid response.
- 503 Service Unavailable: the server is up but refusing requests — usually overload, rate limiting, or maintenance mode.
- 504 Gateway Timeout: the backend accepted the request but took too long to answer — typically a slow database query or a stuck script.
In short: 502 means the backend answered badly, 503 means it is too busy to answer, and 504 means it answered too slowly.
What Causes a 502 Bad Gateway Error?
The usual suspects are a crashed or restarting PHP-FPM process, a server that ran out of memory during a traffic spike, a bad plugin or theme update, or a misconfigured reverse proxy, CDN, or firewall sending requests to the wrong address. The upstream server’s IP or port may also have changed while the gateway config was never updated.
On WordPress sites, the most common trigger is a faulty plugin update or PHP running out of memory. On Cloudflare sites, a 502 often means Cloudflare cannot reach your origin server at all — so the fix starts at the origin.

How to Fix a 502 Bad Gateway Error
Work through these steps in order and reload your site after each one.
1. Wait a minute and refresh
If the error just appeared, the server may be mid-restart after an update. Wait 60 seconds and refresh. If the site loads, the backend was simply restarting.
2. Check whether the site is down for everyone
Open the site on your phone using mobile data, or use a free uptime checker from our free website tools. If it loads elsewhere, the problem is your network or browser cache — clear your cache and try again.
3. Clear your browser cache
A stale cached error page can keep showing a 502 after the site has recovered. Clear cached images and files for the site, then hard-reload with Ctrl+F5.
4. Pause Cloudflare or your CDN
If your site sits behind Cloudflare, switch on Development Mode, or pause Cloudflare for a few minutes. If the site loads with Cloudflare paused, the fault lies between Cloudflare and your origin. Our guide to fixing Cloudflare Error 522 walks through the same origin-connection checks.
5. Deactivate plugins (WordPress)
A bad plugin is the most common WordPress cause. Rename the /wp-content/plugins/ folder via FTP or your host’s file manager to deactivate every plugin at once, then reload. If the site returns, reactivate plugins one by one until the error returns — that plugin is the culprit.
6. Check the error log and restart PHP
On a VPS or dedicated server, read the last lines of the Nginx or Apache error log — it names the exact failure. Restart PHP-FPM and the web server. If the log shows out-of-memory kills, raise the PHP memory limit or upgrade your plan.
7. Contact your host
If nothing above works, open a ticket with the error’s exact time and the log lines you found. Your host can usually tell in minutes whether the fault is a crashed backend or a network issue on their side.
How to Fix 503 and 504 Errors
A 503 usually means overload or maintenance: check for a stuck .maintenance file in your WordPress root, or ask your host to raise your PHP worker limit. A 504 means something is too slow — look for a slow database query or a plugin calling an external API that never answers. If your site is generally slow, start with our guide on why websites load slowly.
How to Prevent 502 Errors in the Future
Test updates on a staging copy first, monitor uptime so you are alerted before visitors complain, and keep headroom in your hosting plan for traffic spikes.
Conclusion
A 502 Bad Gateway error looks alarming, but it is almost always a backend that stopped answering — a crashed PHP process, a bad plugin, or a broken link between your CDN and your origin. Work through the steps above in order, and most 502 errors are fixed in under half an hour. For more fixes, browse the KamiWeb blog.
