Why Do I Keep Getting A Gateway Timeout? | Stop 504 Errors

A gateway timeout happens when a proxy or load balancer waits too long for an upstream reply, so the fix is finding the slow hop and removing that delay.

You click a page, it spins, then you get “Gateway Timeout.” Refreshing may work once, then the error shows up again. That on-and-off pattern is the giveaway: something in the request path is slow under certain conditions, not dead all the time.

This guide explains what the message means, why it repeats, and how to narrow the cause with checks you can do in minutes. It also includes a site-owner checklist for WordPress, APIs, and reverse-proxy stacks.

What A Gateway Timeout Means In Plain Terms

When you visit a site, your browser often talks to a middle server first: a CDN edge, a reverse proxy, or a load balancer. That middle layer then calls an upstream server such as your origin web server, an app service, a database, or a third-party API.

If the middle layer doesn’t receive a timely upstream response, it stops waiting and returns an HTTP 504. MDN’s reference on the HTTP 504 status code describes it as a gateway or proxy not getting a response in time from upstream. That’s why the page that shows the error isn’t always the thing that’s broken.

Why It Can Feel Random

Many timeouts are “tail latency” problems. Most requests finish, then a subset gets stuck behind a busy worker, a slow query, or a long outbound call. You may see the error only during traffic bursts, cron jobs, backups, or deploys.

Two Checks That Save You From Wild Guessing

Check If It’s Local Or Site-Side

  • Open the same URL on mobile data (not Wi-Fi). If it loads there, your local path or DNS is a suspect.
  • Try a private window. This removes extensions and stale session cookies from the picture.
  • If you can, test from a second location or region. If the error appears there too, it’s almost surely site-side.

Write Down The Trigger

Take ten seconds and note what you were doing. A gateway timeout that shows up only on login, checkout, search, or wp-admin points you toward a narrow slice of code and data.

Why You Keep Getting Gateway Timeout Errors Under Load

A 504 is a symptom. The underlying cause is “upstream didn’t answer before the timer ran out.” The job is to figure out which timer, which upstream, and what slowed it down.

Worker Pools Get Saturated

Most web stacks can handle a lot of short requests, then struggle when too many long requests land at once. In PHP-FPM, all workers can become busy, leaving new requests queued. In Node, one blocking operation can stall an event loop. In Java or .NET, thread pools can back up under bursty load.

Database Latency And Locking

A slow query, a missing index, or a lock wait can freeze the whole request path. The gateway waits for the app, the app waits for the database, and time slips away. If the database is healthy but the query plan is bad, you can still see repeat timeouts on one route.

Outbound Calls That Don’t Fail Fast

Checkout, login, shipping rates, image transforms, and analytics can involve remote calls. If one remote call waits too long, your gateway times out first and your user sees a 504. Outbound requests need short connect/read timeouts and bounded retries.

Network Or DNS Issues Between Layers

In multi-network setups, the gateway can reach your origin only through specific routes and ports. Packet loss, slow DNS resolution, or a firewall rule can turn a normal request into a long wait. These issues can show up as “some requests work, some don’t.”

Proxy And Origin Timeouts Don’t Match

One short timeout is enough to cause repeat errors. If a load balancer stops waiting at 30 seconds but your app sometimes needs 45 seconds for a heavy report, users get 504s even though the app would have finished. The fix might be speeding up the route, adjusting timeouts, or both.

Diagnostic Map: Match The Symptom To The Likely Hop

This table helps you convert “Gateway Timeout” into a focused set of checks.

Symptom You Notice Likely Slow Hop Fast Check
Only wp-admin times out Plugin or admin query path Test on staging with plugins disabled
Timeouts spike with traffic Worker saturation Check queue depth and worker usage
Static files load, HTML times out App or database path Hit a lightweight health endpoint
One API route fails often That upstream dependency Trace latency by endpoint in logs/APM
Starts after a deploy New hot path or query Roll back, then compare slow traces
Starts after DNS changes Wrong origin target or blocked port Verify A/AAAA records and firewall rules
Only one network sees it Local DNS cache or upstream proxy Flush DNS, test on mobile data
Proxy shows 504, origin is fine Proxy-to-origin path Test origin directly and compare headers

How To Fix Gateway Timeout Errors As A Site Owner

If you control the site, aim for two outcomes: (1) shorten the slow work so most requests finish quickly, and (2) align timeouts so normal work can complete while broken upstreams fail quickly.

Step 1: Confirm Where The Timeout Starts

Work from the edge toward the origin. If you use a CDN or reverse proxy, test the origin directly from a trusted machine. Cloudflare’s docs on testing origin errors directly outline this approach: bypass the proxy and compare the results.

Step 2: Check Backlogs Before You Tune Timeouts

Timeouts are often backpressure in disguise. Look for queues building up in:

  • Web server: too few workers, slow requests tying them up.
  • App server: thread pool or worker limit reached.
  • Database: slow queries, lock waits, connection pool contention.
  • Background jobs: heavy tasks competing with web requests.

Step 3: Pinpoint The Slow Route

List the slowest requests from the last hour, then group them by route. You’ll often find that a small set of endpoints create most of the pain. Fix those first.

WordPress Notes That Usually Pay Off

  • Test wp-admin on staging with plugins disabled, then add them back one at a time while watching request time.
  • Check scheduled tasks that run on page load. If they stack up, they can slow unrelated requests.
  • Trim heavy admin pages that run broad queries across large tables.

Step 4: Make Outbound Calls Safe

Outbound HTTP calls should fail before your gateway fails. Set connect/read timeouts, retry only safe requests, and cache results that don’t change per user request.

Step 5: Align Timeout Values Across The Stack

After you reduce slow work, make sure timeout windows match your intended behavior. Outer layers should wait long enough for your slowest acceptable requests. Inner layers should fail fast when an upstream is dead.

Layer Setting Names You’ll See What To Confirm
NGINX reverse proxy proxy_connect_timeout, proxy_read_timeout Proxy waits long enough for normal upstream replies
Apache proxy modules ProxyTimeout, Timeout Timeout isn’t shorter than core request work
Load balancer idle timeout, request timeout LB window matches your accepted slow routes
PHP-FPM request_terminate_timeout Runaway scripts are capped; slow logs enabled
App server worker limits, request timeouts Workers aren’t trapped by one long request type
Outbound HTTP client connect timeout, read timeout Remote calls fail before gateways stop waiting
Database statement timeout, lock timeout Bad queries fail cleanly instead of hanging

Why Do I Keep Getting A Gateway Timeout? When It’s Your Network

If the site loads on mobile data but times out on your main network, you’re likely dealing with DNS cache issues, an upstream proxy, or a flaky route.

Clear DNS Cache And Retest

After a site moves hosts or changes IPs, some resolvers lag. Clearing your DNS cache and restarting the browser can remove stale routing. If you manage the network, test with a different resolver to see whether the local DNS server is the slow link.

Check For A Proxy In The Path

Corporate networks often route web traffic through a proxy that enforces its own timeout rules. If only one office sees the issue, the proxy is a prime suspect.

Disable Extensions For One Test

A private window is the simplest test. If the timeout disappears there, an extension or cached session is slowing a core request.

Copy-Ready Checklist For The Next Time A 504 Hits

  1. Test from mobile data. If it works there, start with DNS and network path.
  2. Identify which layer shows the error page (CDN, load balancer, reverse proxy, origin).
  3. Test the origin directly from a trusted host. If origin is slow, focus on server and app logs.
  4. Pull the slowest requests and group by route. Fix one slow route at a time.
  5. Check worker pools and queues: web, app, PHP-FPM, background jobs.
  6. Check database slow queries and lock waits during the same window.
  7. Check outbound calls for long waits and set bounded timeouts.
  8. Align timeouts across layers after the slow work is reduced.

If you’re only visiting the site, a gateway timeout is usually a site-side delay. If you can, send the owner the URL and the time it happened. That single detail makes debugging far quicker.

References & Sources