How to Fix the 502 Bad Gateway Error in WordPress

· first published 2020 · canyonthemes

502 bad gateway error

Few things are as unhelpful as a plain white page reading “502 Bad Gateway”. It tells you something between the visitor and your WordPress site failed, but not what. The good news is that the error is common, rarely means data loss, and can be worked through methodically. This guide explains what the code means and the fixes in the order worth trying.

An occasional 502 during a traffic spike is not a crisis. A recurring one is, because search engine crawlers that repeatedly hit server errors will slow their crawling and, if the errors persist, can drop pages from the index. Fixing the root cause protects both your visitors and your search rankings.

Last updated: 2026 for WordPress 6.8 and PHP 8.2+.

What Is A 502 Error?

Every request a browser sends to a server comes back with an HTTP status code. You never see the successful ones (200), and the familiar failure is 404, meaning the page does not exist. Codes in the 500 range mean the request was understood but something on the server side went wrong.

A 502 specifically means a server acting as a gateway or proxy received an invalid response from the server behind it. On a typical WordPress host that chain is: your browser, a CDN or firewall such as Cloudflare, the web server (NGINX, Apache or LiteSpeed), then PHP-FPM running WordPress. If PHP crashes, times out, or is too busy to answer, the web server reports 502. If Cloudflare cannot reach your web server at all, Cloudflare reports 502. Knowing which layer produced the page helps: a Cloudflare-branded error points at the origin server being unreachable; a bare NGINX error points at PHP.

The message varies by server and browser:

  • Error 502 / HTTP 502
  • 502 Bad Gateway
  • 502 Proxy Error
  • 502 Service Temporarily Overloaded
  • 502 Bad Gateway Cloudflare (with an error reference number)
  • A blank white screen

Common causes are an overloaded server, a PHP process that exceeded its time or memory limit, a plugin or theme fatal error, a misconfigured firewall or CDN, or DNS that points at the wrong place after a migration.

How To Fix 502 Errors

Reload The Page

Start with the obvious. Many 502s are momentary: a PHP worker was busy, the server was restarting, or a deploy was in progress. Wait thirty seconds and reload. Open the site in a private window or on your phone’s mobile data to rule out something local to your machine. If it loads, note the time and move on; if it happens again within the day, continue down this list.

Clear Cache Memory

Caches can preserve an error after the cause is gone. Force-refresh the page with Ctrl+F5 (Windows) or Cmd+Shift+R (Mac), or clear the browser cache from its settings. Then clear your site’s caches: the caching plugin (WP Rocket, LiteSpeed Cache, WP Super Cache), any server-level cache in your hosting panel, and the CDN cache in Cloudflare or your provider’s dashboard. Finally flush your local DNS cache with ipconfig /flushdns on Windows or sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on macOS. Test in a second browser afterwards.

Disable Firewall and CDN

A CDN or web application firewall sits between visitors and your server, so a problem in that layer looks like a server problem. In Cloudflare, switch the domain to Development Mode or temporarily pause Cloudflare on the site (Overview > Advanced Actions) and reload. If the site comes back, check the Cloudflare status page for incidents, confirm the SSL/TLS mode matches your origin (Full or Full Strict when the origin has a valid certificate), and look at the firewall events log for rules blocking legitimate requests. Re-enable once resolved. Do the same test with any security plugin’s firewall, such as Wordfence, if you can reach the dashboard.

Update Your Plugins

A plugin fatal error or an infinite loop kills the PHP process and produces a 502. WordPress 6.x usually catches fatal errors and emails the admin a recovery-mode link, so check your inbox first. Otherwise, deactivate all plugins. If you can log in, use Plugins > select all > Bulk actions > Deactivate. If the dashboard is also returning 502, connect by SFTP or the host’s file manager and rename wp-content/plugins to plugins-off; WordPress will deactivate everything. Rename it back, then reactivate plugins one at a time, reloading the site after each, until the error returns. Update the offender, and if the update does not fix it, contact its support or find a replacement. The full procedure is in our guide to disabling WordPress plugins.

Update Your Themes

If every plugin is cleared, test the theme. Switch to a default theme such as Twenty Twenty-Five from Appearance > Themes, or by renaming the active theme’s folder over SFTP so WordPress falls back. If the error disappears, update the theme; if it is already current, check whether a recent PHP upgrade broke it (deprecated functions become fatal errors in PHP 8.x) and report it to the theme author. If the theme is abandoned, it is time to choose a maintained WordPress theme.

Check Logs And Scripts

Guessing is slower than reading the log. Add these lines to wp-config.php above the “That’s all, stop editing” comment, reproduce the error, then read wp-content/debug.log:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Also check the server error log in your hosting panel; a 502 from PHP-FPM usually leaves a line about a worker exiting, a timeout, or “Allowed memory size exhausted”. The fixes are to raise memory_limit and max_execution_time in PHP settings (defaults of 256M and 300 seconds are reasonable) or, better, to find the script that needs them. Heavy cron jobs, import scripts, and external API calls that hang are frequent culprits. Tools > Site Health lists your current limits and flags anything unusual. Remove the debug lines when finished.

Check Your Hosting Server

If the site is clean and the error continues, the problem is likely the server itself: PHP-FPM out of workers, a neighbour on shared hosting consuming the CPU, or a service restart. Open a ticket with your host and include the exact time of the errors and what you have ruled out; that gets a faster answer than “site down”.

After a migration, 502s often mean DNS. If the domain still points at the old server, or the new server has not been configured for the domain yet, the proxy has nowhere valid to send the request. DNS changes can take up to 24 hours to propagate. If the errors are chronic and the host cannot explain them, that is a signal to move to a plan or provider with more headroom.

Make The Best Use Of WordPress Caching Plugins

Many 502s come down to load: too many requests reaching PHP at once. Page caching fixes that structurally by serving stored HTML for most visits, so PHP is only involved for logged-in users and uncached pages. WP Rocket, LiteSpeed Cache (on LiteSpeed servers) and the caching built into most managed hosts all do this. Combine it with a CDN, keep plugins to what you need, and the server has far less opportunity to fall over. See our post on boosting WordPress performance for the full checklist.

Which Canyon theme fits

Themes cause 502s when they run heavy queries on every page or break under a new PHP version. Ours are tested on PHP 8.2+ and WordPress 6.8, load no bundled sliders or builders, and keep template queries light. If you are replacing a theme that turned out to be the problem, Bloge suits a blog and Business Way suits a company site.

Your Turn

That covers the 502 Bad Gateway error from the simplest fix to the hosting conversation. Work down the list in order, log what you find, and most cases resolve within an hour. If you hit a cause we have not covered, tell us in the comments and we will add it.

Further reading from our partners: Innorobo.

FAQ

Is a 502 error my fault or the host's?
Either. A plugin or theme fatal error, an exhausted memory limit, or a misconfigured CDN are on your side. PHP-FPM running out of workers, a server restart or a noisy neighbour on shared hosting are on the host’s side. Working through the list above tells you which before you open a ticket.
Does a 502 error hurt SEO?
A brief outage does not. Search engines treat 5xx responses as temporary and retry later. If the errors persist for days, crawling slows and pages can be dropped from the index until the site is stable again, so recurring 502s do need fixing.
How do I deactivate plugins when I cannot log in because of the 502?
Connect with SFTP or your host’s file manager and rename the wp-content/plugins folder to something like plugins-off. WordPress deactivates every plugin automatically. Rename it back, then reactivate plugins one at a time from the dashboard to find the one causing the error.