Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting · Explainer

What Causes the 502 Bad Gateway Error in WordPress?

Short answer

A 502 Bad Gateway error means a server acting as a gateway or proxy got an invalid response from the server behind it. In WordPress that usually means PHP-FPM crashed or stopped, the origin server is down, a plugin or script exhausted memory, or a firewall or proxy broke the connection. The gateway itself is up, so the fault sits between it and WordPress.

Key takeaways

  • A 502 means the gateway is up but the server behind it answered badly or not at all.
  • A crashed PHP-FPM worker pool is the most common WordPress cause of site-wide 502s.
  • A 502 on one heavy action points at a script that ran out of memory or time.
  • If the error clears when you pause Cloudflare, the fault is in the proxy-to-origin link.
  • An empty PHP error log at the time of the error points at the server, not at WordPress code.

What does a 502 Bad Gateway error mean in WordPress?

A 502 Bad Gateway error means a gateway or proxy server received an invalid response from the upstream server behind it.

MDN defines the 502 status this way and adds that it is similar to a 500 error, except that it points at a specific place in the request chain: the link between the gateway and the origin server (MDN 502 status).

On a WordPress site the gateway is usually a reverse proxy such as Nginx, a load balancer, or a CDN edge server such as Cloudflare. WordPress itself runs behind that gateway on PHP. When PHP crashes, stops answering, or returns garbage, the gateway has nothing valid to pass on and answers with a 502.

That is the key clue. A 502 means the front door is open but the room behind it is not answering. The fault is almost never in the browser or in the page content itself.

What causes a 502 error on a WordPress site?

The most common WordPress causes are a crashed PHP worker, an origin server that is down, a script that ran out of memory, and a broken proxy or firewall rule.

PHP-FPM, the process manager that runs PHP on many hosts, can crash or run out of workers. When every worker is busy or dead, new requests get no answer and the gateway returns a 502. A restart of PHP-FPM often clears it, which is a sign the workers were the fault.

An origin server that is down is the next cause. If the web server behind the proxy stopped, or the host rebooted the server, the gateway cannot reach WordPress at all.

Cloudflare's 5xx guide notes that the cause is not always in the origin server's own logs, and the logs of load balancers, caches, proxies and firewalls in between should also be checked (Cloudflare 5xx errors).

Memory is a third cause. PHP ships with a default memory_limit of 128M, according to the PHP manual. A script that passes that limit dies, and if it dies during the response the gateway may report a 502 instead of a PHP error.

Bad proxy, DNS or firewall settings form the fourth group. A wrong upstream address in Nginx, a DNS record that points at the wrong server, or a firewall rule that blocks the proxy can each break the same link.

MDN notes that client-side network errors are the exception, mostly when the site works for other visitors and the visitor uses a VPN or custom network setup (MDN 502 status).

How can you tell which cause you have?

Start by checking whether the error is constant or comes and goes, and whether it hits the whole site or only some pages.

A 502 on every page that clears after a few minutes points at a server restart, a PHP-FPM crash, or a brief overload. A 502 that only appears on one heavy action, such as importing content or saving a large page, points at a script that runs out of memory or time.

ClueLikely causeWhere to check
Whole site fails, then recoversPHP-FPM crash or server restartHost status, PHP error log
Only one heavy action failsMemory or time limit in a scriptError log, wp-config.php
Error only behind CloudflareProxy or origin connection faultCloudflare error analytics
Error after a server or DNS changeWrong upstream or DNS recordNginx config, DNS settings
Error only for you, not othersYour network, VPN or firewallBrowser without VPN, another network
Error mentions the gateway by nameGateway cannot reach originHost server logs

If the site works for other visitors, the fault may be on your side. MDN advises checking network settings, firewall setup, proxy settings and DNS in that case (MDN 502 status).

If the error is site-wide, ask the host whether PHP-FPM or the web server restarted at the time of the first error. That one answer often ends the search.

What does the error log tell you about a 502?

The PHP error log and the server error log usually show whether PHP died, ran out of memory, or never answered at all.

WordPress writes PHP errors to wp-content/debug.log when WP_DEBUG and WP_DEBUG_LOG are true in wp-config.php, with WP_DEBUG_DISPLAY set to false so errors stay out of the page HTML (WordPress debugging handbook).

A log line that says “Allowed memory size exhausted” points at the memory limit. WordPress tries to give PHP 40MB on a single site and 64MB on multisite, per the wp-config handbook. A heavy plugin or import can pass that limit and kill the request.

A log line with a fatal error and a plugin or theme path points at that code. A log with no entries at all around the time of the error is also useful: it suggests PHP never ran, which points at the server, the proxy, or a crashed PHP worker rather than at WordPress code.

The Nginx or Apache error log sits on the server side and may show “upstream prematurely closed connection” or a connect failure. Only the host can read that log on most shared plans, so share the exact time and URL of the error when you ask.

Our guide on how to fix ERR_CONNECTION_REFUSED covers the related case where the browser cannot reach the server at all.

Why does a crashed PHP worker cause a 502?

A crashed PHP worker causes a 502 because the gateway has no PHP process left to hand the request to.

On PHP-FPM setups, a fixed pool of worker processes handles all PHP requests. Each worker takes one request at a time. When a worker crashes, runs out of memory, or gets stuck on a slow task, the pool shrinks.

When the pool is empty, the gateway waits, gets nothing back, and answers with a 502. The WordPress common errors guide describes the same pattern for timeouts: a site that tries to do more than the server can manage, common on shared hosting with a restricted memory limit.

The clue is the pattern. If the error appears under load and clears when traffic drops, the worker pool is too small or a slow script is holding workers.

If it appears after a deploy, a bad plugin may be crashing workers one by one. The fix steps for the WordPress side are in our guide on how to fix the 502 Bad Gateway error.

How do Cloudflare and other proxies cause a 502?

A proxy causes a 502 when it cannot reach the origin server, or when the origin sends back a broken response.

Cloudflare sits between visitors and the origin on many WordPress sites. If the origin server is down, the Cloudflare edge has nothing to serve and returns a 502. The same happens if a firewall rule blocks Cloudflare's IP addresses from reaching the origin.

The Cloudflare dashboard can show which side failed. Its error analytics filter by edge status code and origin status code, so you can see whether the 502 came from the edge or the origin (Cloudflare 5xx errors).

A 502 that appears only when Cloudflare is active and clears when you pause Cloudflare points at the proxy-to-origin link. A 502 that stays when Cloudflare is paused points at the origin server itself. That one comparison splits the problem in half.

The related Cloudflare errors help too. Error 521 means the origin refused the connection, and it is covered in our guide on how to fix Cloudflare error 521.

Error 522 means the connection timed out, and it is covered in our guide on how to fix Cloudflare error 522.

When is a 502 a hosting problem, not a WordPress problem?

A 502 is a hosting problem when nothing in WordPress changed, the error hits every page, and the logs show no WordPress error.

Server restarts, PHP-FPM crashes, a full disk, and a host that killed PHP workers for high CPU use all produce site-wide 502s with no WordPress log entry.

WordPress.org recommends PHP 8.3 or greater and MySQL 8.4 or MariaDB 10.11 or greater as of November 2026, so a host running far older versions can also be a source of crashes (WordPress requirements).

The test is simple. If wp-admin fails, the front end fails, and the error log is empty at the time of the error, WordPress code is probably not the cause. If a single plugin action fails while the rest of the site loads, the cause is more likely in WordPress.

Ask the host for the server error log entries at the exact time of the error, and whether PHP-FPM restarted. Cloudflare's guide advises giving the host the error code, the time and timezone, and the failing URL (Cloudflare 5xx errors).

If the host reports high CPU use, our guide on how to fix high CPU usage covers the WordPress side.

What mistakes should you avoid?

Do not keep reloading the page and hoping, and do not change several things at once.

Reloading a 502 during a server fault adds load to a server that is already struggling. Wait a minute, then load once and note the exact time so the host can match it to the server log.

Do not change plugins, themes, DNS and proxy settings in one go. Each change hides the effect of the others, and you will not know which one fixed the error. Change one thing, check, and note the result.

Do not raise the PHP memory limit as a reflex. The wp-config handbook warns that raising the limit can hide the real fault, which returns as you add more plugins. Check the log first.

Finally, do not blame the CDN before checking the origin. Pause the proxy once, load the site directly, and see if the error stays. That single check separates a proxy fault from an origin fault.

Frequently asked questions

What is the difference between a 502 and a 504 error?

A 502 means the gateway got a bad response from the server behind it, while a 504 means the gateway got no response in time. Both point at the link between the proxy and the origin. A 502 often means PHP crashed or the origin is down, while a 504 often means a slow script or a busy server. The logs tell you which one applies.

Can a 502 error fix itself?

Sometimes, if the cause was a brief PHP-FPM crash or a server restart. If the error stays for more than a few minutes, it will not clear on its own. A crashed worker, a down origin server and a broken proxy setting all need a fix, so check the error log and the host status page instead of waiting.

Can a 502 error be caused by my own internet connection?

Yes, if the site works for others but not for you. Try another network, turn off your VPN, and clear your browser cache. MDN notes that client network errors are the exception, mostly when the site works for other visitors and the visitor uses a VPN or custom network setup.

Is one 502 error something to worry about?

A single 502 now and then is usually a brief server restart and is not worth chasing. A 502 that repeats, follows a pattern, or blocks wp-admin needs attention. Repeated 502s point at a crashing PHP worker, a low memory limit, or a proxy that cannot reach the origin.

Should I contact my host about a 502 error?

Yes. Give the host the exact error code, the time and timezone it happened, the failing URL, and the last lines of your PHP error log. Cloudflare's own guide lists these as the details a host needs. Without the time, the host cannot match your error to the server log.

Sources

  1. 502 Bad Gateway MDN Web Docs
  2. Cloudflare 5xx errors Cloudflare Docs
  3. Debugging in WordPress WordPress Developer Resources
  4. Editing wp-config.php WordPress Developer Resources
  5. Description of core php.ini directives PHP Manual

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test