
🔧 How to fix the 502 Bad Gateway error in WordPress
You visit your site and see a white screen with three words: "502 Bad Gateway." Traffic is flowing, but visitors see an error instead of content. Sales stall, SEO rankings slide down, and you waste time guessing.
The 502 error looks scary, but under the hood it is simply a communication failure between servers. Your site is not broken, data has not vanished, and in most cases the fix takes five to fifteen minutes. Below is a step-by-step guide that walks you from the simplest checks to deeper diagnostics.
💡 Quick overview:
- Refresh the page and verify whether the hosting server is down
- Clear your browser cache and temporarily disable the CDN
- If the error persists, disable plugins via FTP and check the theme
- Reset .htaccess and contact your host when everything else fails
What is a 502 Bad Gateway error
When you open a site, the browser sends an HTTP request. On the server side a reverse proxy (Nginx, Apache) receives it and distributes requests among the application server (PHP), the database, the static web server, and the CDN. Each node handles its part and returns the result to the proxy server. The proxy assembles the response and delivers it to the browser, and the page loads.
A 502 error occurs when one of the servers in that chain returns an invalid response to the proxy server. The proxy cannot assemble the page and displays "Bad Gateway." The browser honestly reports that the gateway between servers received something unexpected.
Externally the error can take various forms: "502 Bad Gateway," "502 Service Temporarily Overloaded," "HTTP 502," "Nginx 502 Bad Gateway," "Proxy Error." The essence is the same: somewhere in the chain there is a break.
Why the 502 error occurs
The causes are almost always server-side, but sometimes your own actions on the site trigger it:
- Server overload. A sudden traffic spike exhausts hosting resources, and PHP processes cannot keep up with the request queue.
- Faulty plugin or theme. Code that causes a fatal PHP error terminates the application server's response, and the proxy receives nothing.
- CDN issues. Cloudflare, KeyCDN, or another content delivery service cannot connect to the origin server and returns a 502.
- Incorrect DNS records. After changing hosts or updating DNS servers, records have not propagated yet, so the site is temporarily unreachable.
- Corrupted.htaccess. Broken syntax or conflicting rewrite rules break request handling.
- PHP memory limit exhausted. A heavy plugin or script consumes all available memory, and the process crashes.
Now let us walk through each fix step by step, from the quickest to the more complex.
Step 1. Refresh the page
First and simplest: press F5 or Ctrl+R. If the error was caused by a brief server glitch, the repeated request will succeed. Try opening the site in another browser or on mobile data; this rules out a problem on your end.
Check whether the site works for the rest of the world using isup.me or Down For Everyone Or Just Me. If the service shows that the site is down only for you, the problem is local, so move on. If the site is unavailable for everyone, the hosting server has most likely crashed or a block has been applied at the provider level.
Step 2. Clear the browser cache
The browser caches not only images and styles but also erroneous server responses. A hard refresh (Ctrl+F5 on Windows, Cmd+Shift+R on macOS) forces the browser to request the page again, bypassing the local cache.
If a hard refresh did not help, clear the cache entirely. In Chrome: Settings → Privacy and security → Clear browsing data → "Cached images and files." We covered detailed instructions for various browsers and clearing the cache on the WordPress side in a separate guide.
Step 3. Temporarily disable the CDN
Content delivery networks such as Cloudflare or KeyCDN route traffic through their own servers. If a failure occurs on the CDN side or an incorrect firewall rule is configured, visitors will see a 502 even when the origin server is fully operational.
To test this hypothesis, pause the CDN in its control panel. Cloudflare: go to Overview → Pause Cloudflare. KeyCDN and similar services: find the Disable or Pause button in the panel. After disabling, refresh your site. If the error disappears, the problem is on the CDN side; contact their support.
While the CDN is disabled, the site works directly from your hosting, so speed may drop slightly, but availability will be restored. We compared popular CDN services and their setup in an article about free CDNs for WordPress.
Step 4. Check DNS settings
After changing hosts or updating NS records, DNS information propagates across the network over a period ranging from several hours to 48 hours. During this time some visitors may land on the old server, which does not respond or responds incorrectly.
If you recently migrated your site, wait 24 hours; that is usually enough. Additionally, flush your local DNS cache: on Windows open Command Prompt and run ipconfig /flushdns; on macOS run sudo dscacheutil -flushcache and sudo killall -HUP mDNSResponder. Then refresh the page.
Step 5. Disable plugins via FTP
The most common cause of a 502 on WordPress is a plugin conflict. A single problematic plugin can cause a fatal PHP error that brings down the entire site. Since the WordPress admin panel is inaccessible during a 502, you will need to disable plugins through the file system.
Connect to the server via FTP (using FileZilla, WinSCP) or open File Manager in cPanel. Navigate to the site's root folder (usually public_html):

Go into wp-content and find the plugins folder. Rename it, for example to plugins.old. This instantly disables all plugins at once. Plugin data is not deleted when renaming the folder; settings remain in the database:

Refresh the site. If it works, the problem is one of the plugins. Rename the folder back to plugins, go to the admin panel, and enable plugins one by one, checking the site after each activation. Once you find the culprit, delete it via FTP or replace it with an alternative.
Step 6. Check the active theme
If disabling plugins did not help, the next suspect is the theme. Incorrect code in functions.php or a conflict with the PHP version can similarly cause a fatal error and a 502.
Go back to the site's root folder → wp-content → themes. Find the folder of the active theme and rename it (for example, add .old at the end):

WordPress will automatically switch to the default theme (Twenty Twenty-Four, Twenty Twenty-Five, or similar). Refresh the site; if the error is gone, the problem is the theme. Contact the theme developer or restore a backup. After diagnosing, rename the folder back to its original name.
A detailed algorithm for checking themes and locating conflicting code is described in the guide to troubleshooting WordPress theme issues.
Step 7. Reset the.htaccess file
A corrupted .htaccess is a frequent but less obvious cause of a 502. Rewrite rules added by a caching plugin or security plugin can conflict with each other. A single syntax error in this file, and the server returns a 502 on all requests.
Connect via FTP and locate the .htaccess file in the site's root folder. Download a backup copy to your computer, then delete the file from the server. Go to the WordPress admin panel, navigate to Settings → Permalinks, and click "Save Changes" (without changing anything). WordPress will create a new .htaccess with a clean set of rules.
If the error appeared immediately after installing a caching plugin (WP Rocket, W3 Total Cache, LiteSpeed Cache), check the section with that plugin's rules in .htaccess; it is usually wrapped in comments like # BEGIN W3TC / # END W3TC. Delete that block, save the file, and refresh the site.
Step 8. Contact your hosting provider
If none of the previous steps helped, the problem is most likely on the server side. Contact your host's technical support and provide the domain, the time the error appeared, and which steps you have already taken. The more detail you give, the faster the engineers will find the cause.
Ask them to check the PHP and web server error logs for the period when the 502 appeared. The logs almost always show exactly which script or module is causing the failure. On inexpensive shared hosting plans the cause may simply be a lack of resources: one site on the server consumes all the memory, and the rest receive a 502. In that case it makes sense to consider moving to a VPS or cloud hosting with guaranteed resources.
Video guide
Watch a visual walkthrough of diagnosing and fixing the 502 error from the first step to the last in this video:
⁉️🤔 Frequently asked questions
Can a 502 error resolve on its own?
Yes, if the cause is a brief overload of the hosting server. Providers monitor load and automatically restart problematic processes within one to five minutes. Refresh the page after a couple of minutes; in half the cases the error disappears without any action on your part.
How do I distinguish a 502 from other server errors?
A 502 Bad Gateway is an error at the proxy server level (Nginx/Apache), not the application itself. A 500 Internal Server Error indicates a problem directly in the PHP code or configuration. A 503 Service Unavailable means the server is temporarily not accepting requests, usually during scheduled maintenance. A 504 Gateway Timeout means the server did not receive a response from the upstream server within the allotted time. For the user the difference comes down to diagnostics: a 500 is most often fixed by editing code, while a 502 is fixed by restoring communication between servers.
Do I need to restore the site from a backup for a 502?
A backup is a last resort, not a first step. Before deploying a backup, follow steps 5, 6, and 7 of this guide: disable plugins, check the theme, reset
.htaccess. In the vast majority of cases a 502 is resolved without restoring a backup. Deploy a backup only if the error appeared immediately after updating WordPress, plugins, or a theme and rolling back changes via FTP is not possible.
Can I prevent 502 errors in the future?
Partially yes. Use quality hosting with enough PHP memory (the recommended minimum is 256 MB). Set up uptime monitoring for your site through UptimeRobot or a similar service; you will learn about a problem before visitors report it. Before installing or updating plugins, make a quick backup. And keep FTP access handy: when the admin panel is down, it is the only way to quickly disable problematic code.
What to do if nothing helped?
The eight steps above cover nearly all scenarios for a 502 Bad Gateway on WordPress. If you have checked plugins, theme, DNS, and CDN, reset .htaccess, and the error remains, the problem is deeper, and you cannot do without hosting engineers.
The correct sequence saves hours: first rule out local causes (cache, browser, CDN), then server-side causes (plugins, theme, .htaccess), and only then escalate to the provider. Save this guide in your bookmarks; a 502 has a habit of returning at the worst possible moment, and quick access to the checklist will save you a lot of stress.



