Errors 504 and 524 mean essentially the same thing: the server took too long to respond and the intermediary stopped waiting. The difference is who gave up waiting — your web server or Cloudflare. Let's look at where these errors come from and how to fix them — first for visitors, then for site owners running a VPS.
What 504 Gateway Timeout means
504 Gateway Timeout is returned by an intermediary server — usually Nginx — when the application behind it (PHP-FPM, Node.js, Python) doesn't respond within the allotted time. By default Nginx waits 60 seconds. If building the page takes longer, the visitor sees a 504.
What it looks like: 504 Gateway Time-out with nginx underneath, "HTTP Error 504" in the browser, or "Gateway Timeout" on a hosting page.
What Cloudflare error 524 means
Error 524: A timeout occurred is a Cloudflare error. It means Cloudflare connected to your server successfully but didn't receive an HTTP response within 100 seconds (the limit on most plans). The server is alive, but the request is taking too long.
How 504 and 524 differ from 502
| Code | Who returns it | What happened |
|---|---|---|
| 502 Bad Gateway | Nginx / proxy | The application returned an invalid response or crashed |
| 504 Gateway Timeout | Nginx / proxy | The application didn't respond within the timeout |
| 524 | Cloudflare | The server accepted the connection but didn't respond within 100 seconds |
Seeing a 502 instead? Read our guide to the 502 Bad Gateway error.
What to do as a visitor
- Wait a minute and reload — it's often a short spike in load.
- Check whether the site opens on your phone over mobile data. If not, the problem is on the site's side.
- If you submitted a form or uploaded a file, don't resubmit right away: the action may have completed even though the response didn't arrive.
- Let the site owner know if the error persists for more than 10–15 minutes.
Server-side causes of 504 and 524
- Heavy database queries — reports, exports, searches without indexes.
- Slow external calls — the app waits for a payment API, CRM or another service.
- Too few PHP-FPM workers — every process is busy and new requests queue up.
- Not enough CPU or RAM — the server starts swapping and everything slows down.
- Timeouts set too low in Nginx for operations that legitimately take a while (imports, file generation).
- Firewall blocking connections — for 524, check that Cloudflare's IP ranges aren't being throttled.
How to fix it: steps for site owners
1. Find the slow request in the logs
Check /var/log/nginx/error.log for lines like upstream timed out (110: Connection timed out) along with the page URL. Enable the PHP-FPM slow log (request_slowlog_timeout = 10s) and the MySQL slow query log to see exactly what's slow.
2. Check server resources
htop, free -m and iostat show whether the server is hitting CPU, memory or disk limits. If load sits at 100% all the time, optimization will only help partly — you need a server with headroom.
3. Raise timeouts only where justified
For specific long operations you can raise the Nginx limits:
location /admin/export {
proxy_read_timeout 300s;
fastcgi_read_timeout 300s;
}
Match PHP's max_execution_time to them. Raising timeouts for the whole site is a bad idea: the problem gets hidden while visitors keep waiting.
4. Move long tasks to the background
Exports, mailings and image processing should run in a queue (cron, Redis + a worker, Celery, Laravel Queue): the user gets an immediate response while the task runs in the background. This is the main way to get rid of 524, since Cloudflare's 100-second limit can't be changed on regular plans.
5. Add workers and caching
Increase pm.max_children in PHP-FPM within your memory budget, enable OPcache and page caching (FastCGI cache, Redis). Database indexes often speed up heavy queries by orders of magnitude.
6. Check the firewall for Cloudflare
If the site sits behind Cloudflare, make sure its IP ranges aren't cut off by fail2ban or connection limits — otherwise requests will hang.
How to prevent it
- Uptime and response-time monitoring (Uptime Kuma, Zabbix) with alerts.
- Resource headroom: CPU under 60–70% at normal load, 20–30% of memory free.
- Fast NVMe storage and a high CPU clock for PHP and databases.
If 504 and 524 errors come from a lack of resources, the easiest fix is a server with headroom: a PSB Hosting VPS on NVMe or a Hi-CPU VPS for heavy projects.
FAQ
Is a 504 error caused by my internet connection?
Almost never. A 504 happens between the site's servers. If the site doesn't open over mobile data either, wait for it to be fixed.
Can I raise Cloudflare's 100-second limit?
Not on regular plans. The fix is to respond faster or move the long operation to a background task.
Does a 504 hurt SEO?
Occasional errors don't. If search bots get 504s for several days, pages can drop out of the index.
Why does a 504 only appear in the admin panel?
That's usually where heavy operations run: reports, imports, plugin updates. Raise the timeout for those URLs and move long tasks to the background.









