TRLet’s talk
← Argo Ajans

WordPress

How to fix the WordPress 502 Bad Gateway error

Ramazan Göksu ·

How to fix the WordPress 502 Bad Gateway error

Short answer

A WordPress 502 Bad Gateway error means a gateway layer in front of your site, Nginx, a CDN, or a reverse proxy, couldn’t get a valid response from the backend PHP server. WordPress’s own code is often fine; the problem sits in the communication and timeout layer before the request ever reaches WordPress.

The most common causes are a sudden traffic spike overloading the server, PHP-FPM failing to respond to a request in time, a badly coded plugin or theme, or a CDN in front of the site with proxy timeout settings that don’t match the server’s own. The order below moves from the most common cause to the rarest; don’t skip back to an earlier step before trying the next one, because a 502 error often results from more than one small issue stacking up.

Why does WordPress show a 502 Bad Gateway error?

The message in the browser always looks the same (“502 Bad Gateway”), but the cause can come from a few different layers:

  • The server getting overloaded by a sudden traffic spike or a bot crawl
  • PHP-FPM failing to respond within its configured timeout window, because of a heavy query, a large file operation, or a stuck background task
  • A badly coded plugin or theme consuming too much server CPU or RAM
  • A CDN or firewall in front of the site, Cloudflare for example, with a proxy timeout setting that doesn’t match the server’s own
  • A temporary server-side maintenance window, restart, or configuration error

What they share is that the problem sits in the network and processing layers a request passes through, not in WordPress’s database or content. That also explains why the error often clears itself once server load drops, and why it sometimes keeps coming back.

The difference between a 502 error and a 500 Internal Server Error

These two are easy to confuse, but they come from different layers. A 500 Internal Server Error points to a problem in the PHP code itself, a broken plugin, an incompatible theme, or a core file, the server receives and processes the request, but crashes while handling it. A 502 Bad Gateway means PHP was never reached at all, or timed out, the gateway (Nginx or a CDN) gets no valid response from the backend whatsoever.

This distinction matters in practice: fixing a 500 error usually means debugging a plugin or theme (turning on WP_DEBUG, for example), while fixing a 502 error means looking at server resources, timeout settings, and the network layer instead. We cover the plugin-debugging steps in detail in our guide to the WordPress critical error.

Run the simple checks first

Before you dig deeper, a few quick tests tell you whether the error is temporary or persistent. Reload the page, clear your browser cache, and try accessing the site from a different browser or device. If the error only shows up for you, the cause is probably your local network or a stale DNS cache; if it shows up for everyone, there’s a real issue at the server or gateway level. Clear your WordPress caching plugin’s cache at the same time, since a corrupted cache file can sometimes mimic the same error.

Temporarily disable your CDN or firewall

If your site sits behind Cloudflare or a similar CDN or firewall, that layer’s own proxy timeout or caching rule could be triggering the error. Switch to “development mode” in your CDN’s dashboard temporarily, or point DNS directly at your server to test the site without the CDN in front of it. If the error disappears without the CDN, the cause is its proxy timeout setting, and you’ll need to match that value to your server’s own timeout (usually 60-120 seconds).

Deactivate plugins and your theme one by one

If the CDN check didn’t resolve it, a plugin or theme conflict is the next likely cause. If you can reach the dashboard, deactivate every plugin at once and see if the error disappears; if it does, reactivate them one at a time to find the one responsible. If you can’t log in, do the same thing through FTP by temporarily renaming plugin folders inside wp-content/plugins one at a time. Backup, search, and analytics plugins that run heavy database queries are common triggers for this error in particular.

Test your theme the same way. Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and see if the error persists; if it clears up, a heavy function or query call in your current theme is responsible.

Check PHP-FPM timeout and resource limits

If plugins and themes check out clean, the issue may sit in the server’s PHP-FPM configuration. PHP-FPM terminates requests that don’t get a response within a configured window (request_terminate_timeout), and that’s exactly what makes Nginx return a 502. Check this timeout value and PHP’s memory limit (memory_limit) in your hosting panel or server configuration files; a memory shortage can surface as a 502 in some setups and a 500 in others, so it’s worth checking both together. For a detailed walkthrough of the memory-limit side of this, see our guide to the allowed memory size error.

On shared hosting, you may not be able to change these limits from your own panel, in which case you’ll need to ask your hosting provider to raise the timeout and process-count settings for your PHP-FPM pool.

Server overload and traffic spikes

When server resources, CPU, RAM, or the number of concurrent processes, run out during a sudden spike in traffic, a campaign, a bot crawl, or a DDoS attempt, PHP-FPM has no capacity left to handle new requests, and a 502 error follows. Check your hosting panel’s resource usage graphs to see whether a load spike coincided with the time the error occurred. If this keeps repeating on a regular basis, it may mean your current hosting plan can’t keep up with your site’s traffic, and a resource upgrade is worth considering.

Check the error logs

If your host gives you access to error logs, or PHP/Nginx logs through your server panel, they’ll show the exact second the error occurred and which request triggered it. These logs usually point directly to which PHP script timed out or which memory error occurred, letting you confirm the steps above instead of guessing.

What if nothing works?

If you’ve worked through every step above and the WordPress 502 Bad Gateway error is still there, the cause is most likely something in the server infrastructure you can’t fully see from your own panel: resource usage from other sites on a shared server, PHP-FPM pool configuration, or a hardware issue at the gateway level. At that point, the fastest path is sharing the exact time, frequency, and affected pages with your hosting support team, their access to server logs can surface the exact cause you can’t see.

Avoiding the 502 Bad Gateway error next time

Most of this is preventable. Review your hosting resources ahead of any campaign period that expects a traffic spike; test plugin and theme updates in a staging environment before pushing them live; and match your CDN’s proxy timeout setting to your server’s own. As our guide to the WordPress 500 Internal Server Error also shows, most WordPress server errors trace back to the same three sources: insufficient resources, timeouts, and configuration.

If you want to see how WordPress’s own Site Health tool detects server connectivity issues, WordPress’s official class-wp-site-health.php source code contains the get_test_loopback_requests() function; it tests whether your site can send a request back to its own server (a loopback request), and a failed test is exactly why scheduled tasks (WP-Cron) and the plugin/theme editor can stop working, a direct example of how WordPress itself detects 502-style connectivity issues.

Next step

A WordPress 502 Bad Gateway error looks alarming, but it’s usually a connection issue resolved by fixing server resources or timeout settings, with no risk of data loss. If the problem keeps recurring server-side, or you want a broader review of your hosting setup’s performance, our group company Web Tasarım Ofisi supports WordPress maintenance and server performance work.

To talk through your site’s technical setup or a custom software need, take a look at our custom software service or get in touch with Argo Ajans.

Frequently asked questions

What does a WordPress 502 Bad Gateway error mean?

It means a gateway layer in front of your site (Nginx, a CDN, or a reverse proxy) couldn't get a valid response from the backend server, usually PHP-FPM. WordPress itself is often fine; the problem sits in the communication layer before the request ever reaches WordPress.

Is a 502 error the same as a 500 Internal Server Error?

No. A 500 error usually points to a problem in the PHP code itself (a plugin, theme, or core file). A 502 error means PHP was never reached, or didn't respond in time, the cause sits in a different layer.

Does a 502 error cause data loss?

No, it doesn't cause data loss on its own. It's a connection and timeout issue, your database and files aren't affected. Still, changes made during a long outage might not save, so it's safe to stop working once you notice the error.

What should I check if I use a CDN or Cloudflare?

Start by temporarily disabling the CDN, or switching it to development mode, and testing whether you can reach the site directly. If the error disappears, the CDN's proxy timeout settings or caching rules are likely triggering it.

What should I do if nothing works?

Share the exact time the error occurred, which pages triggered it, and which steps you've already tried with your hosting provider's support team. Most 502 errors trace back to server resource usage or PHP-FPM configuration, and only your host can see those logs.

Need help with this?

Custom Software

Explore the serviceGet in touch
Good work starts with a conversation.

Let’s make
it matter.

Izmir office
Tariş Cd. (1497. Sok.) No. 5C Ofis P22
35230 Alsancak, İzmir, Türkiye
UK office
167 Sheen Lane
SW14 8NA London, United Kingdom
Kayseri office
Sahabiye Mh. Buyurkan Sok. No.29
38015 Kocasinan, Kayseri, Türkiye
Send your project brief