What 504 Gateway Timeout Means
A proxy, load balancer, or CDN sent the request on to the backend and set a timer. The timer ran out before a complete answer came back, so the proxy answered the visitor with 504. Compare 502 Bad Gateway, where the backend refused or broke the connection: 502 is "no valid answer", 504 is "no answer in time".
What Visitors Can Try
- Wait and reload: a short load peak may already be over.
- Do not resend a form or payment at once: the action may have finished on the server even though the page timed out. Check your account or e-mail first.
- Try another network or switch off a VPN to rule out your own connection.
Step 1: Confirm Where It Timed Out
sudo grep -i "timed out" /var/log/nginx/error.log | tail -n 20The log names the upstream that did not answer and the request that was waiting. Note the address: a slow report page and a slow home page have different causes.
Step 2: Find the Slow Part of the Backend
- Database queries: run
SHOW FULL PROCESSLIST;in MySQL or MariaDB while the page loads and look for long-running queries; turn on the slow query log to catch them over time. - Calls to outside services: a payment, mail, or search API that hangs holds the whole request. Time it from the server with
curl -o /dev/null -s -w "%{time_.total}\n" https://api.example.com/ - Locks: a backup or import that locks tables makes ordinary pages wait.
Step 3: Know the Timeout on Each Layer
Every layer has its own limit, and the shortest one decides:
- Nginx to an HTTP backend:
proxy_, 60 seconds unless set.read_ timeout - Nginx to PHP-FPM:
fastcgi_, also 60 seconds unless set.read_ timeout - Apache proxy:
ProxyTimeout, which follows the server'sTimeoutunless set. - PHP itself:
max_in php.ini, andexecution_ time request_in the PHP-FPM pool.terminate_ timeout - Load balancer or CDN: an idle or response timeout set in its own settings.
Raising a limit for one slow admin page is reasonable; raise it in that location only:
location /admin/reports/ {
proxy_pass http://127.0.0.1:3000;
proxy_read_timeout 180s;
}Test with sudo nginx -t and reload. The Nginx details are in 504 Gateway Timeout in Nginx.
Step 4: Check Whether the Server Is Overloaded
uptime
free -h
topA load average far above the number of cores, or memory swapping hard, slows every request. Linux load average explains the numbers. If all PHP-FPM workers are busy, new requests queue until the proxy gives up; the pool size is covered in PHP-FPM.
Step 5: Packets Dropped Between Proxy and Backend
A firewall rule that drops traffic, instead of rejecting it, makes the proxy wait for a connection that never opens. Test from the proxy:
nc -zv 10.0.0.5 3000The nc tool comes from the netcat-openbsd package on Debian and Ubuntu and from nmap-ncat on AlmaLinux and Rocky Linux. A quick success message is good; a long wait followed by a timeout points to a firewall or routing problem on the path.
When a CDN Sits in Front
A CDN has its own time limit for your server's answer. Cloudflare shows it as error 524, and raising your server's limits does not change the CDN's.
Move Long Jobs Out of the Request
Imports, exports, large reports, and bulk e-mail do not belong in a web request. Accept the job, put it in a queue, answer at once (status 202 is made for this), and let a background worker run it. The worker can be a systemd service or a cron job, and the page can poll for the result.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations