sfw/fix
504 high

504 Gateway Timeout

A 504 means a gateway waited for the backend and the backend never answered in time. The fix is finding what’s slow.

What you see

HTTP 504 — Gateway Timeout
The upstream server failed to send a request in the time allowed by the server.

What’s actually happening

A proxy or CDN asked your origin for a page and gave up waiting. The request isn’t broken — it’s just too slow. Common on heavy pages, slow database queries, or long-running operations triggered by a page load.

Common causes

  • A slow database query or unindexed table
  • A long-running script (import, report, external API call) tied to a page request
  • The origin server is overloaded and responding slowly
  • Proxy/CDN timeout set lower than the backend’s response time

How to fix it

  1. Find the slow requestThe access log + a query monitor reveal which URL and which query are slow. Optimize the query (add an index) or cache its result.
  2. Move long tasks off the requestImports, emails, and API calls shouldn’t run inside a page load. Push them to a background queue or cron so the page returns instantly.
  3. Raise timeouts as a stopgapIncreasing the proxy/PHP timeout buys time but masks the real issue — use it to stop the bleeding while you optimize.
Related errors