WordPress Errors

502 Bad Gateway and 504 Gateway Timeout: What They Mean for Your Site

These two errors look similar and mean different things. Here is how to tell a 502 bad gateway from a 504 timeout, what causes each, and how much of it you can actually fix yourself.

Get Shielded
19 Jul 2026 6 min read
502 Bad Gateway and 504 Gateway Timeout: What They Mean for Your Site

Both errors take your site offline. Both mention a gateway. Both look like something you cannot do anything about. But they describe genuinely different failures, and knowing which you have saves a lot of wasted effort.

A 502 bad gateway means one server got an invalid response from another. A 504 means it got no response at all before giving up waiting.

The setup that produces them

Modern WordPress hosting usually has more than one server involved. A web server such as Nginx sits at the front. Behind it, PHP processes your code. There may also be a CDN or a proxy in front of everything.

The front-end server is the "gateway". When it passes a request backwards and does not get a usable answer, it has to tell the visitor something — and that something is a 502 or a 504.

Neither error tells you what went wrong. They tell you that one part of the stack could not get a straight answer from another part. The cause is always further back.

502 Bad Gateway: an invalid response

The backend answered, but with something the gateway could not use — usually because the PHP process crashed mid-request.

Common causes:

  • PHP crashed — a fatal error, a memory exhaustion, or a segmentation fault
  • PHP-FPM is down or overloaded, with no worker processes available to take the request
  • A bad server configuration, particularly after a change
  • A CDN or proxy problem between the visitor and your host

If a 502 appears intermittently under load, it usually means PHP-FPM has run out of workers. If it appears consistently, something is crashing every time.

504 Gateway Timeout: no response at all

The backend never answered within the allowed window. Something is taking too long rather than failing outright.

Common causes:

  • A slow database query that never completes
  • A plugin calling an external API that is not responding
  • A heavy operation — an import, a backup, a bulk update — running during a page load
  • Server resources exhausted, so nothing gets enough CPU to finish
  • A genuine traffic spike beyond what the server can handle

The distinction matters practically: a 502 means find what is crashing, a 504 means find what is slow.

What you can do yourself

Start with the timing

When did it begin, and does it affect everything or only certain pages? A 504 on your shop's checkout but nowhere else points at something specific to checkout — a payment gateway API not responding, for instance.

Read the error log

As always, the log knows more than the error page. Look in your hosting panel's error log, and enable WordPress debug logging:

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

Then read wp-content/debug.log. For a 502, look for fatal errors. For a 504, look for what was running when it stalled.

Disable plugins in batches

If you cannot reach the dashboard, rename wp-content/plugins to disable everything, confirm the site returns, then re-enable in groups.

Plugins that call external services are prime suspects for 504s — social feeds, shipping calculators, currency converters, review widgets. When the third-party service is slow, your page waits.

Check for a runaway process

Backup plugins, import tools and statistics plugins sometimes run during page loads rather than in the background. If the error began after installing one, that is a strong lead.

Clear caches

Both your caching plugin and your CDN. A cached error response can keep serving long after the underlying problem is resolved.

What only your host can do

Be realistic about the boundary here, because a lot of advice pretends otherwise.

PHP-FPM worker limits, Nginx timeout values, server-level resource allocation and restarting stuck services are all above your account on most hosting. If you have worked through the site-level causes, the next step is a support ticket, not more configuration files.

When you contact them, give specifics: the exact error, when it started, whether it is constant or intermittent, which URLs are affected, and anything from the error log. That turns a vague ticket into an actionable one.

The pattern that means it is hosting

Some signals point clearly at the plan rather than the site.

  • Errors appear at predictable busy times and clear when traffic drops
  • Other sites on the same account fail simultaneously
  • Your host mentions resource limits or worker exhaustion
  • The site is well optimised and still fails under moderate traffic

That last one is the honest signal that a site has outgrown its hosting. Our guide to choosing WordPress hosting covers what to move to.

When it is not capacity at all

Worth ruling out, particularly for sudden onset with no traffic growth.

A compromised site consumes resources for work you did not authorise — sending spam in volume, mining cryptocurrency, or being used in an attack against someone else. All of that exhausts PHP workers and produces exactly these errors.

Treat it as suspicious if errors began abruptly with no changes and no traffic increase, if your host reports unusual resource usage or outbound traffic, or if the site was already behaving oddly. Our guide to removing malware from WordPress covers what to check.

Reducing the odds

  1. Cache aggressively — cached pages never reach PHP, so they cannot exhaust workers
  2. Audit plugins making external calls, and make sure they fail gracefully rather than hanging
  3. Move heavy jobs to background cron rather than page loads
  4. Keep the database tidy so queries stay fast
  5. Right-size your hosting for actual peak traffic, not average
  6. Run uptime monitoring, since intermittent 502s are easy to miss entirely

That last point matters. Intermittent gateway errors often affect a slice of visitors while the site looks fine whenever you check it — the losses are invisible unless something is watching.

If it keeps happening

Recurring 502 and 504 errors are rarely random. They usually trace back to one plugin, one query, or hosting that no longer fits the site — and identifying which needs log access rather than guesswork.

Our WordPress error fixing service finds the actual cause, and our managed website plans include the monitoring and performance work that stops them recurring.

Send us your web address and when the errors appear, and we will tell you what is behind them.

Get Shielded

We build, host, secure and monitor business websites — cleaning up hacks and keeping sites online for clients across the UK, USA, Australia and the UAE.

Keep reading

Chat on WhatsApp