504 Gateway Timeout and Error 524: Causes and How to Fix Them

504 Gateway Timeout and Error 524: Causes and How to Fix Them

  1. Home
  2. Blogs
  3. 504 Gateway Timeout and Error 524: Causes and How to Fix Them

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

  1. Wait a minute and reload — it's often a short spike in load.
  2. Check whether the site opens on your phone over mobile data. If not, the problem is on the site's side.
  3. 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.
  4. 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.

Related articles

How to Automate CAPTCHA Solving on a VPS with CaptchaAI

How to Automate CAPTCHA Solving on a VPS with CaptchaAI

Partner content. Prepared by the CaptchaAI team. Moving an automation project to a VPS solves one problem: the application no longer depends on someone keeping a laptop open. But a server that sta

VPN vs VPS: What's the Difference and Which One Do You Need?

VPN vs VPS: What's the Difference and Which One Do You Need?

VPN and VPS are easy to mix up: the abbreviations look alike, and both come up in conversations about servers and security. In reality they are completely different things. Let's look at the differenc

Mobile Proxies on a VPS: Building Reliable Workflows for Social Media and Automation

Mobile Proxies on a VPS: Building Reliable Workflows for Social Media and Automation

Teams that manage dozens of social media accounts or run automation eventually arrive at the same setup: a server that runs 24/7 and mobile proxies that carry that traffic to the internet. Here is how

500 Internal Server Error: Causes and How to Fix It

500 Internal Server Error: Causes and How to Fix It

500 Internal Server Error means something went wrong on the server — but the server won't tell the visitor what. It's the least informative error: it has dozens of possible causes. The good news

Buysellacc.com: a Platform for MMO Accounts and Digital Services

Buysellacc.com: a Platform for MMO Accounts and Digital Services

Partner content. Prepared by the Buysellacc team. Buysellacc.com is a platform with an automated system for MMO accounts and digital services. It works for individuals, collaborators, resellers and b

How to Connect to a Server via SSH: Windows, macOS and Linux Step by Step

How to Connect to a Server via SSH: Windows, macOS and Linux Step by Step

SSH is the standard way to manage a VPS or dedicated server: you use it to install software, edit configs, read logs and restart services. This guide shows how to connect to a server via SSH from Wind

Money Safe Review: a Service for Manually Built White Pages for Media Buyers

Money Safe Review: a Service for Manually Built White Pages for Media Buyers

Partner content. Prepared by the Money Safe team. In affiliate marketing, there haven’t been any one-size-fits-all solutions that guarantee passing moderation for quite some time. The algorithm

502 Bad Gateway Error: What It Means and How to Fix It

502 Bad Gateway Error: What It Means and How to Fix It

502 Bad Gateway is one of the most common website errors: you open a page and get a blank screen saying "502 Bad Gateway". Let's look at what it means, who is to blame — the browser, the site or

ProxiesTrust.com: Multi-Country Proxies with Stable Performance

ProxiesTrust.com: Multi-Country Proxies with Stable Performance

Partner content. Prepared by the ProxiesTrust team. ProxiesTrust.com is a multi-country proxy service that partners value for its stability and performance. It is built for long-term use at a reasona

Telegram