Black Friday: 60% off yearly plans with code BF2026, until November 30. See the deal

Troubleshooting

504 Gateway Timeout: what it means and how to fix it

A 504 Gateway Timeout means a server acting as a gateway or proxy did not get a response from the upstream server in time. The upstream is usually slow or hung, or a timeout setting is lower than the work takes. Reloading rarely helps if the slow request repeats.

The short answer
  • No response arrived in time. Compare 502, which means an invalid response arrived.
  • Visitors: retry later, check a second device or network, and review VPN and proxy settings.
  • Owners: find the slow request, then fix it or raise the timeout deliberately.
Try the website status checkerFree, live, no signup

How is 504 different from 502 and 408?

Timeout and gateway status codes
CodeWho timed outMeaning
504 Gateway TimeoutThe proxy waited for upstreamNo upstream response in time
502 Bad GatewayNobody timed outUpstream answered with an invalid response
408 Request TimeoutThe server waited for the clientThe server closed an idle connection
524 (Cloudflare)Cloudflare waited for your originConnected, but no response before the read timeout

See MDN: 504 Gateway Timeout and Cloudflare error 524.

What causes a 504 error?

Slow query or job

A report, export or database query takes longer than the proxy is willing to wait.

Hung or overloaded app server

All workers are busy, so the request waits in a queue until the proxy gives up.

Slow third-party call

The app waits on an external API or payment provider that does not answer.

Network path problem

Packet loss or a firewall drop between proxy and upstream stalls the connection.

Slow DNS inside the stack

The app server waits on name lookups for a database or API host.

Timeout too low

The proxy timeout is shorter than legitimate requests need.

Which nginx timeouts control a 504?

nginx defaults from the official documentation
# defaults: 60s each
proxy_connect_timeout 60s;   # establish the connection (usually cannot exceed 75s)
proxy_send_timeout    60s;   # between two writes to the upstream
proxy_read_timeout    60s;   # between two reads from the upstream

# PHP-FPM / FastCGI: same defaults
fastcgi_read_timeout  60s;

The read and send timeouts apply between successive operations, not to the whole response (nginx proxy module). Raise a timeout only after you know why the request is slow.

How do you fix a 504, in order?

  1. 01

    Find which URLs time out

    One slow endpoint points at a query or job. Every URL points at the upstream or network.

  2. 02

    Test the upstream directly

    Request the app server bypassing the proxy and time it with curl -w "%{time_total}\n" -o /dev/null -s URL.

  3. 03

    Read proxy and app logs

    Match the proxy timeout line to the app log entry for the same request and see where time went.

  4. 04

    Fix the slow work

    Index the query, cache the result, or move long jobs to a background queue and poll for status.

  5. 05

    Raise the timeout only if justified

    For legitimate long requests, raise the proxy read timeout. Cloudflare also has its own limits, see the 524 row above.

  6. 06

    Rule out the client side

    If others can load the site, check your VPN, proxy, firewall and DNS settings, as MDN suggests.

Common questions

What does 504 Gateway Timeout mean?

It means a gateway or proxy waited for the upstream server and got no response within its time limit. The proxy itself works. Either the upstream is too slow or down, or the proxy timeout is shorter than the request needs.

Can I fix a 504 error as a visitor?

Usually not. Reload once, try again in a few minutes, and test from another network. If the site works for others, check your VPN, proxy, firewall and DNS settings. Otherwise tell the site owner.

What is the difference between 502 and 504?

Both come from a gateway. A 502 means the upstream replied with something invalid. A 504 means it did not reply in time. A 502 suggests a crashed or misconfigured upstream, while a 504 suggests a slow or hung one.

Should I just increase the timeout?

Only if the request is legitimately long. A higher timeout hides a slow query and ties up workers, which can cause 503s under load. Fix or background the slow work first, then size timeouts to the real maximum.

Why do I get a 504 behind Cloudflare?

Cloudflare returns 524 when your origin accepts the connection but does not respond before its read timeout, which is 125 seconds by default. A true 504 can also come from your own proxy, load balancer or host in front of the origin.

Watch your domains automatically

Aepto monitors expiry, DNS, SSL and uptime for every domain you own and alerts you when something changes. Free for 3 domains.