HTTP error reference
504 Gateway Timeout
A 504 Gateway Timeout means a proxy, load balancer or CDN passed your request to the server behind it and gave up waiting for an answer. Something is slow, not necessarily broken: a heavy database query, a long import, a hung call to another service, or a server with every worker busy.
If you are visiting the site
As a visitor, wait a minute and try again. If the page does something heavy, like an export or a big search, try a smaller request. Repeated 504s are for the site owner to fix.
Common causes
A slow request
One page or API call takes longer than the proxy is willing to wait. Reports, exports, imports and unindexed database queries are the usual suspects.
Every worker is busy
When all PHP-FPM or app workers are occupied, new requests queue until the proxy times out. A traffic spike or a few stuck requests can cause this.
A hung call to another service
The application waits on a payment gateway, mail server or API that never replies, and the visitor’s request waits with it.
Timeouts that do not line up
Nginx waits 60 seconds by default (proxy_read_timeout and fastcgi_read_timeout). Cloudflare waits 125 seconds by default before showing its own 524 error. If PHP is allowed to run longer than the proxy waits, the proxy gives up first.
How to fix it
Find the slow request first
- Match the time of the 504 in the proxy log to the application log or slow-query log, and find which URL or job took too long.
- Fix the cause where you can: add a database index, cache the result, or move long jobs (imports, exports, emails) to a background queue.
Nginx
- Only after that, raise proxy_read_timeout or fastcgi_read_timeout for the specific location that needs it, not for the whole site.
- Keep PHP’s max_execution_time and the FPM request_terminate_timeout in line with the Nginx timeout so a stuck script is stopped rather than left running.
Apache
- For proxied backends, the Timeout and ProxyTimeout directives control how long Apache waits.
Cloudflare
- A Cloudflare-branded 504 page came from your own server; a blank, unbranded one came from Cloudflare. Cloudflare’s own 524 means it connected to your server but got no response within its proxy read timeout (125 seconds by default).
- Requests that need minutes should not go through the browser at all; run them in the background and let the page check for the result.
Quick checklist
Find the slow upstream request and its duration.
Check database queries, external calls and overloaded workers.
Raise timeouts only after understanding the workload and failure mode.
Questions about 504 errors
Should I just raise the timeout?
Only once you know why the request is slow. A longer timeout hides the problem and ties up workers for longer, which can turn one slow page into a site-wide outage.
What is the difference between 504 and 524?
A 504 can come from any gateway. A 524 is Cloudflare’s own code: it connected to your server, but your server took longer than Cloudflare’s read timeout to answer.
Is a 504 a server or a network problem?
Usually the server: it accepted the request but took too long. Network faults more often show up as connection errors or Cloudflare’s 522.