How To Fix “502 Bad Gateway” In WordPress

How To Fix “502 Bad Gateway” In WordPress

Last modified: June 8, 2026

FAQ
Fiverr freelancers

A 502 Bad Gateway error means your web server received an invalid response from an upstream server while trying to process your page request. In a WordPress setup, this typically involves your server, a proxy layer (like Cloudflare or a load balancer), and the PHP process that powers WordPress. If any link in that chain breaks down or sends back a malformed response, you get a 502.

It’s different from a 504 Gateway Timeout, which happens when the upstream server is too slow. A 502 usually means the upstream server sent something back, but it was corrupt or empty, caused by a plugin conflict, a PHP crash, a CDN misconfiguration, or a server resource limit being hit.

The most common cause depends on your hosting setup. If your site is behind Cloudflare or another CDN and the 502 appeared after a configuration change, start with Step 3. If the error came on suddenly with no changes, a temporary server overload (Step 1) or a recently updated plugin (Step 4) are more likely. If the error is persistent and appeared after a server migration or hosting upgrade, go straight to Step 5. Otherwise, work through the fixes below in order and test your site after each one.

Show More

* This button will show the rest of the post and open up an offer from a vendor

Step One: Retry Your Website

Before anything else, wait two to three minutes and reload your site. A 502 is sometimes a brief spike: the server hit a resource limit under heavy traffic, processed the backlog, and recovered on its own. Refreshing too quickly can give you another cached error page.

If you’re using a CDN, also purge the CDN cache; some providers cache error responses. In Cloudflare, go to Caching > Configuration and click Purge Everything. In other CDNs, look for a cache flush or purge option in the dashboard. Then reload your site again.

If the error clears up, it was a temporary server load issue. You can monitor server resource usage in your hosting dashboard to see if it’s recurring.

Step Two: Browser Cache

Your browser caches pages, including error pages. Even if the issue has already been resolved server-side, your browser might still be showing you the cached 502 page.

Clear your browser cache completely:

  • Chrome/Edge: Press Ctrl+Shift+Delete (Windows) or Cmd+Shift+Delete (Mac), select “Cached images and files,” and clear.
  • Firefox: Same keyboard shortcut, then select “Cache.”
  • Safari: Go to Develop > Empty Caches (you may need to enable the Develop menu in Preferences > Advanced).

Alternatively, open an incognito/private window and visit your site, private windows don’t use the standard browser cache. If your site loads there, the cache was the issue.

Step Three: Disable Your CDN Or Firewall

If you’re running a CDN or web application firewall (WAF), it can sometimes generate a 502 when it can’t reach your origin server or misinterprets a response.

For Cloudflare users: Log in to your Cloudflare dashboard, select your site, scroll down the Overview tab and click Pause Cloudflare on Site. This routes traffic directly to your origin server, bypassing Cloudflare entirely. Reload your site, if the 502 disappears, Cloudflare is the culprit.

When Cloudflare is paused and the site loads, contact Cloudflare support or check your firewall rules and Page Rules for anything that might be causing proxy errors. Common causes include overly aggressive WAF rules or SSL/TLS mode mismatches (make sure it’s set to Full (strict) rather than Flexible).

For other CDN providers, look for a “Pause” or “Bypass” option in their dashboard, or temporarily update your DNS to point directly to your hosting IP.

Step Four: Plugins/Themes

A broken or outdated plugin is one of the most common triggers for a 502 in WordPress. The safest way to test this is through the WordPress admin:

Method 1, WordPress Admin (preferred):
Go to Plugins > Installed Plugins, select all plugins using the checkbox at the top, then choose Deactivate from the Bulk Actions menu. Reload your site. If the 502 clears, reactivate plugins one at a time, reloading after each, until the error returns, that’s your culprit plugin.

Method 2, FTP (use if WP admin is inaccessible):
Connect to your server via FTP or SFTP. Navigate to wp-content/ and rename the plugins folder to plugins_disabled. Reload your site to test. Then rename the folder back to plugins, WordPress will show all plugins as deactivated, letting you reactivate them individually.

For themes: Switch to a default WordPress theme (Twenty Twenty-Four) via Appearance > Themes. If your current theme is causing the error, this will confirm it. Via FTP, rename your active theme folder inside wp-content/themes/ to force WordPress to fall back to the default.

After isolating the problem plugin or theme, check for available updates or contact the developer.

Step Five: Check With Your Host

If none of the above fixes the issue, it’s likely a server-side resource problem. Two quick things to try before calling your host:

1. Increase your PHP memory limit:
A PHP process that runs out of memory can return a 502. Add the following line to your wp-config.php file (above the line that says “That’s all, stop editing!”):

define('WP_MEMORY_LIMIT', '256M');

If that doesn’t help, also add:

define('WP_MAX_MEMORY_LIMIT', '512M');

Save the file and reload your site.

2. Check your error logs:
Your server error log often identifies the exact cause. In cPanel, go to Metrics > Errors to see the most recent PHP and server errors. Look for lines mentioning memory exhausted, timeout, a specific plugin file, or upstream. The error log will usually point you directly at the problematic component.

If both of these fail, contact your hosting provider with a copy of the relevant error log lines. A PHP-FPM crash, misconfigured Nginx upstream block, or server resource limit is something only your host can adjust at the server level.

Final Word: How to Fix 502 Bad Gateway in WordPress

Work through the fixes above in order; most 502 errors come down to a temporary server hiccup, a CDN issue, or a misbehaving plugin, all of which you can resolve without a developer. The PHP memory limit fix and error log check (Step 5) catch a lot of cases that the earlier steps miss.

If your site keeps throwing 502 errors even after trying everything here, it’s time for a hosting upgrade or migration. A reliable managed WordPress host like Kinsta or WP Engine handles PHP memory, load balancing, and upstream configuration at the infrastructure level, which eliminates most of the causes behind a persistent 502. If you’re instead seeing a 503 Service Unavailable error, that guide covers server resource limits, Cloudflare-specific fixes, and wp-cron issues as well.

Recap:
Save 4 Later
Email liked links to yourself

    Stay Updated with WordPress Insights

    Get the latest WordPress tips, theme reviews, and industry deals delivered to your inbox.