504 Gateway Timeout

Updated 11 October 2026

Short answer

A 504 means the front server (Nginx, a load balancer, or Cloudflare) waited for your app to respond and ran out of patience. Your app is running, but something inside it is too slow: usually a database query, a call to an outside service, or a server too busy to keep up. Find which pages time out, then find the slow step in them.

What's the problem

Pages hang for a long time, then show "504 Gateway Timeout". Often it's only certain pages, such as reports, searches, exports or checkout, or only at busy times.

Why it happens

  • A slow database query, often one that got slower as your data grew, or is missing an index.
  • Waiting on an outside service: a payment provider, email API, or another system that's slow or down.
  • The server is overloaded and requests queue up.
  • A long job is being run during the page request, like generating a big PDF or importing a file.
  • The timeout is set very short on the front server.

How to fix it

  1. Find which URLs time out. If it's one page, the slow step is in that page's code.
  2. Check your app's logs for slow requests and the queries or calls they make.
  3. Check the database: look for slow queries and missing indexes. See database timeout.
  4. Check outside services the page depends on, and their status pages.
  5. Move long jobs to the background. Send the user a "we'll email you when it's ready" instead of making them wait.
  6. Only raise the timeout as a stopgap. It hides the problem; the page is still slow.

What Preventionlabs checks

One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; up to 50 pages from your sitemap, listing any that fail or are slow, plus broken links on them. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; which requests the firewall blocked, by Cloudflare's own rule names; recent deploys and account changes, with their times.

Run your free report

Your first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.

Sources

  1. MDN Web Docs: 504 Gateway TimeoutreferenceThis is similar to a 502 Bad Gateway , except that in a 504 status, the proxy or gateway did not receive any HTTP response from the origin within a certain time.
← All of Error codes