Gateway Time-out Error Code 504: What It Means and How to Fix It

You click a link. The tab spins, spins some more, and what finally loads is a plain white page with “504 Gateway Time-out” sitting near the top left. No logo. Nothing to click.

Here’s the thing about this one: the fault is on the server side nine times out of ten. One server asked another server for something, waited, gave up. Your laptop barely factors into it.

This blog post is for both visitors and website owners. You’ll learn what a 504 Gateway Time-out means and how to fix it, whichever side of the screen you’re on.

What a 504 Gateway Time-out Error Actually Means

Most websites today don’t live on one machine. Your request probably hits a CDN first, maybe a reverse proxy or a load balancer after that, and only then reaches the box with the real files and database on it.

That middle server has a patience limit. It passes your request to the origin, waits, and if nothing comes back before the clock runs out, it gives up and hands your browser a 504.

Picture a courier with a delivery window, banging on a warehouse door. No answer. He writes up a failed delivery slip and drives off.

The slip is your 504. The quiet warehouse is the origin server.

Any code starting with 5 points at the server, not your device. You may see it written as “HTTP Error 504”, “Gateway Timeout Error”, or a Cloudflare page titled “Error 504 Gateway time-out”. Same problem underneath, just a different messenger.

Why 504 Errors Happen in the First Place

Loading one page can touch a CDN, pass through a proxy, wake up PHP, and then run whatever database queries that page asks for. All of it runs against the same clock.

One link hangs and the gateway quits waiting. That’s a 504.

Server racks behind a 504 gateway timeout

Most of the time the stall comes from something on this list:

  • Server overload: CPU or RAM pinned, requests stacking up, answers showing up long after anyone cared.
  • Exhausted PHP workers: Every worker is busy, so new requests wait in line until the gateway loses patience.
  • Slow database queries: One unindexed or bloated query can hold a page for 30 seconds. Sometimes longer.
  • Long-running scripts: Imports, exports, backups, bulk edits. These blow past the gateway’s limit all the time.
  • Misfiring cron jobs: A scheduled task kicks off during a traffic spike and response times cross the line.
  • Firewall or security rules: Block a proxy or CDN IP range by accident and the gateway never hears back.
  • Bot traffic or DDoS: Automated floods chew through the same resources real visitors are waiting on.
  • DNS changes after a migration: Traffic could still be aimed at an old origin. Or a new one that isn’t finished.
  • CDN or proxy misconfiguration: Wrong origin address, wrong port, or a timeout shorter than the site actually needs.
  • A faulty plugin or theme: One bad update and yesterday’s fast page crawls.
  • Host-side outages: The upstream server is down. Nothing you do on your end changes that.

Some of these shrug off the standard fix list. Clearing a cache won’t bring an offline host back, and reinstalling a plugin won’t fit a 90-second import into a 60-second window.

For those, the answer is waiting it out or running the job on a different schedule.

504 vs 502, 503, 522 and 524: Knowing the Difference

People mix these up constantly. Here is how they actually differ:

Code What It Means Typical Cause
504 Gateway Timeout No response from upstream in time Slow or overloaded origin server
502 Bad Gateway Invalid response from upstream Crashed process or broken proxy config
503 Service Unavailable Server can’t handle the request now Overload or maintenance mode
Cloudflare 522 Connection to origin timed out Origin unreachable, blocked or down
Cloudflare 524 Origin connected but replied too slowly Response took longer than 100 seconds

Sort them by what the upstream actually did. A 504 means silence. Nothing came back before the clock ran out.

With a 502, something did come back, it was just malformed or truncated enough that the proxy refused it. And 503 is the server answering on purpose to say it has no capacity right now, so go away. (Seeing one of those instead? Here’s what a 500 Internal Server Error means and why 503 backend fetch failed shows up.)

Cloudflare muddies this. Put the same slow app behind it and you get a 524 where plain Nginx would have handed you a 504, because Cloudflare did reach your server and then quit waiting at about 100 seconds.

A 522 is a different animal. No connection ever happened. Sort out which of those two you’re looking at before you start digging, or you’ll burn an afternoon on the wrong server.

How to Fix a 504 Error as a Visitor

Work down this list. The moment the page loads, you’re done.

Six checks sit between you and the point where it stops being your problem to solve.

1. Wait a Minute and Reload the Page

A lot of 504s are just a traffic spike that passes on its own. Waiting a minute beats fiddling with settings, most days.

F5 does a normal reload. Want a clean copy that ignores the cache? Ctrl+F5 on Windows, Cmd+Shift+R on a Mac.

Page comes back after a try or two? That was load trouble, nothing more. You don’t have to change a thing.

2. Check Whether the Site Is Down for Everyone

Don’t blame your connection yet. Find out first whether anybody else can reach the site, and Down for Everyone or Just Me will tell you in about five seconds.

Down for everybody? Then stop here and try again later. But if the checker says the site is up, something between your network and that server is falling over.

3. Try a Different Browser, Device or Network

Swapping networks is the fastest single test you have. Kill Wi-Fi on your phone and pull the site up over mobile data.

Loads fine there? Look at your router, your DNS, or the route your ISP is taking. Dead everywhere, on every device, means the site itself is broken.

4. Turn Off Your VPN or Proxy

A VPN or proxy adds extra stops between you and the site. Some exit nodes get rate limited by origin servers, and a few get blocked outright.

Switch them off and you’ve removed an entire layer of guesswork.

Windows 11 manual proxy setup settings

Here is the path on Windows:

  1. Open Settings and go to Network & internet.
  2. Select Proxy.
  3. Switch off Use a proxy server and Automatically detect settings.
  4. Close the VPN app if it’s still connected. Then reload.

On a Mac the same toggles live somewhere else. Look under System Settings > Network > Details > Proxies.

Page loads fine with the VPN off? Then the problem sat with the server you were routed through, and your machine is fine. Switch the VPN on again, except choose a different location this time.

5. Flush Your DNS Cache and Switch DNS Servers

Your machine keeps its own copy of DNS records. When one goes stale, it can point you at a server that stopped answering days ago.

Clearing it takes about a minute, and it fixes more sites than you’d guess.

Here is the path on Windows:

  1. Search for cmd, right click Command Prompt, then choose Run as administrator.
  2. Type ipconfig /flushdns and hit Enter.
  3. A confirmation line prints out. Now reload the site.

Mac users run dscacheutil -flushcache in Terminal instead. Still broken? Point your network adapter at 1.1.1.1 or 8.8.8.8 and try the page one more time.

6. Restart Your Router and Clear Browser Cache

Unplug the router. Unplug the modem too, while you’re at it. Give it thirty seconds before you plug them back in, and don’t test anything until the lights stop blinking and go solid.

Next up: clear the cache and cookies, but just for the site that’s giving you trouble. Chrome hides this behind the padlock icon next to the address bar (on some versions it’s a set of sliders instead). Click it, choose “Cookies and site data,” then “Manage on-device site data,” and delete what’s listed. Reload the page.

This one fixes it more often than you’d think, especially when a site loads fine on your phone but not your laptop.

But if all six steps come up empty, the fault is on the website’s end, not yours. So wait it out, or poke them on social media. That really is what’s left.

How to Fix a 504 Error on Your Own Website

These go fastest first. Save the config edits for last, once you actually know what’s dragging.

1. Check Your Hosting Status and Contact Support

Hosts usually spot an outage before customers do, and most run a live status page. Check that first. An hour spent debugging someone else’s outage is an hour gone.

Then open a ticket, and be specific in it. Ask whether the server hit a resource limit, what the error log shows for your domain, and whether PHP workers ran out. Vague tickets get vague replies.

2. Review Server Resource Usage and PHP Workers

Most control panels graph CPU, memory and process usage over the past few days. If the spikes line up with the times your site went dark, the server ran out of headroom. Simple as that.

Exhausted PHP workers look different on those graphs. Traffic looks ordinary, CPU looks fine, and yet requests queue up and die anyway, because every last worker is tied up on something slow.

3. Read the Server Error Logs

Logs turn guesswork into facts. A timeout entry usually reads “upstream timed out” and names the request that stalled, while a fatal PHP error gives you a file path and a line number instead.

So pull the error log from your hosting panel. Or go straight to the Nginx or Apache log path your host documents.

Then match the 504’s timestamp against whatever landed around it. The slow request tends to name itself. (Watch for the same URL showing up again and again a few seconds apart.)

4. Temporarily Pause Cloudflare or Your CDN

Got a proxy sitting in front of the site? Then the question is whether it caused the error or merely passed it along. Switching it off for five minutes answers that.

Pause Cloudflare on Site option in Cloudflare dashboard

The test takes about four clicks:

  1. Sign in at Cloudflare, then click the domain you’re testing.
  2. On the Overview page, scroll until the right-hand panel comes into view.
  3. Hit Pause Cloudflare on Site to bypass it completely. Or just toggle Development Mode if skipping cache is all you need.
  4. Wait a few minutes. Then load the site with the proxy out of the picture.

Error gone while paused? That points at the CDN, so check origin address and timeout values there. A 504 that survives the pause is coming from the origin server instead.

5. Rule Out a Plugin or Theme Conflict

A single badly behaved plugin can sit on a request until the gateway stops waiting. Killing all of them at once is the fastest way to prove it. This one fixes it more often than you’d think.

Follow these steps on WordPress:

  1. Get in over FTP, or open the File Manager your host provides.
  2. Go into wp-content, then rename the plugins folder to plugins-old.
  3. Load the site. Working again? Make an empty plugins folder and move them back one at a time.
  4. Still broken with every plugin off? Switch to a default theme.

Same trick applies elsewhere. Turn off the extensions or modules in bulk, then flip them back on one at a time until the error returns. Whatever you switched on last is the culprit.

6. Look for Slow Database Queries and Long-Running Scripts

Do the 504s only hit during imports, backups, bulk edits, or report runs? Then nothing is actually broken. The script is just slower than the gateway’s patience, and the gateway wins.

So split the work into smaller batches. Command line beats the browser for this kind of thing, and backups belong in off-peak hours. A stuck cron job firing over and over will do it too, and those stack up fast on shared hosting.

7. Increase Server and PHP Timeout Values

Raising timeout values just buys you breathing room. Nothing runs faster. Think of it as a bandage you leave on while you track down the slow thing, and copy the config file somewhere safe first.

Nginx

Find the server or location block that actually handles the request. Bump proxy_read_timeout, proxy_connect_timeout, and fastcgi_read_timeout there. Pick a number your slowest real request can finish inside of.

Then save, test the config, and reload.

Apache and PHP

Apache uses a single Timeout directive, set in the config file. PHP ignores that one entirely. It watches max_execution_time instead, which you’ll find in php.ini or under your host’s PHP settings panel.

One catch. A lot of managed hosts enforce their own ceiling on that value, so the number you type may not be the number you get.

8. Check Firewall Rules, Bot Traffic and DNS After a Migration

Security plugins and server firewalls sometimes block the exact IP ranges your CDN sends traffic from. So the gateway sits there waiting on a request nobody will ever answer.

Whitelist your proxy’s ranges. Then re-read any rate limiting rule you added in the past week or two, because those get forgotten fast.

Traffic floods cause the same symptom from the other direction. Open the access logs. One IP hitting the same URL hundreds of times, or some odd user agent doing it, will stand out fast.

Timing matters too. If the 504s started about a day after a migration, pull your DNS records and confirm they still point at the right origin.

Then wait out propagation before you change anything else. (This one fixes it more often than you’d think.)

How to Prevent 504 Errors From Coming Back

When 504s keep showing up, the server is usually maxed out already. One busy afternoon is all it takes to push it over.

Build in some slack ahead of time. A traffic spike stays a spike that way, instead of turning into downtime.

Here’s what usually keeps the error from returning:

  • Page caching: Static copies mean most visitors never touch PHP or the database at all.
  • Object caching: Results from repeat queries get saved and handed back, so your database isn’t answering the same question forty times in a row during a rush.
  • A CDN: Hand off images, CSS and scripts to it. Your origin then has room left for actual page requests.
  • Uptime monitoring: You hear about the 504 from an alert. Not from an annoyed customer’s email.
  • A hosting plan that matches real traffic: A reliable host with enough PHP workers heads off most resource-related timeouts.
  • A lean plugin stack: Every plugin you add brings queries with it, and the abandoned ones bring risk too.
  • Heavy jobs at odd hours: Schedule backups, imports and big report runs for the quiet window. Around 3 a.m. works for most sites.
  • Database cleanup on a schedule: Old post revisions pile up. So do stale transients and spam comments. Clear them so queries stay quick.

And if the 504s keep coming after all of that? Then the hosting tier is probably the wall you keep hitting. More tuning buys you less and less at that point, and moving to better infrastructure buys you more.

Do 504 Errors Hurt Your SEO?

A quick 504 here and there? Google treats that as a temporary hiccup. Googlebot comes back later, and a handful of them won’t dent your rankings.

Now, days of 5xx responses. That’s a real problem. Googlebot slows down its crawling rather than hammer a server that’s already in trouble, so fresh pages and edits go unnoticed for a while.

And if the outage runs long enough, Google may drop those pages from the index.

So watch the server error report in Search Console. A spike there usually shows up before anyone emails you about the site being down. (That early warning is worth more than it sounds.)

Frequently Asked Questions

Is a 504 error my fault or the website’s fault?

Usually the site. A gateway or proxy throws the error when the origin server stays silent past the timeout window, and there’s nothing you can click to fix that.

Your own setup can do it too. A VPN, maybe a stale DNS record. That’s a thin slice of cases.

How long does a 504 Gateway Time-out usually last?

Traffic spikes tend to pass quickly. A minute or two, sometimes less than that.

But a host outage, a bad deploy, a DNS change in flight? Those can run for hours. Refreshing every so often is about the only way to tell the two apart from where you sit.

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

Both come from a proxy that couldn’t get a usable answer. With a 502 Bad Gateway, the upstream box did respond, but what came back was malformed, so the proxy threw it out.

A 504 Gateway Timeout is the quieter failure. Nothing came back before the clock ran out. Bad reply versus no reply.

Can a VPN cause a 504 error?

It can. Doesn’t happen often.

Shared VPN exit nodes collect rate limits and firewall blocks from origin servers, and then the gateway just sits there waiting on a response that never shows up.

Kill the VPN connection, or hop to a different server location. Takes under a minute to rule out.

Why do I only get a 504 on wp-admin and not the front end?

Odds are your front end is coming off a cache, so the origin barely gets touched. The admin area doesn’t get that treatment. Every click there means live PHP and fresh database queries.

So wp-admin is where trouble surfaces first when a query drags or a plugin goes heavy. A drained worker pool looks exactly the same from the browser.

Final Thoughts

A 504 Gateway Time-out is a waiting problem. Nothing is corrupt, nothing got deleted. Something upstream ran slow and the server out front gave up on it.

If you’re just visiting the site, your options are short: reload, try a different network (phone data works fine for this), and check a down-detector style site to see if everyone else is stuck too. That covers most of what you can actually control.

Site owners should work in order. Host status first. Then resources and logs, then CDN, then plugins and slow scripts, and save timeout edits for near the end.

Watch the exact symptom. A 504 during a product import points somewhere very different than a 504 that takes down every page. Chasing both with the same fix burns an afternoon.

Which one is it on your end? Site-wide, or only when you click something specific? Comments are open, and the exact wording on your screen helps.