504 means a proxy waited too long for the website's server. Visitors: reload later; it's not your connection. Site owners: find the slow request (database queries, external APIs), fix it, and only then consider raising proxy timeouts.

The short explanation

A 504 means a proxy or gateway waited for the website's application server and gave up before it replied. The backend is usually alive but too slow: heavy database queries, slow external APIs or overloaded workers.

Raising timeouts can hide the symptom; making the slow request faster is the real fix.

Signs of the problem

  • “504 Gateway Timeout” after a long pause on one specific page or report.
  • It worsens as data grows or under load.
  • Fast pages are fine; one heavy endpoint times out.

What causes it

  • A slow database query or missing index on a large table.
  • A blocking call to a slow third-party API with no timeout.
  • The backend is overloaded and cannot get to the request in time.
  • Proxy read/send timeouts set lower than the real work takes.

Fixes to try, in order

  1. Profile the slow endpoint: log query times and external-call durations to find what exceeds the timeout.
  2. As a stopgap, raise the proxy read/send timeout (e.g. proxy_read_timeout) so the page can complete while you fix the root cause.
  3. Add database indexes, cache expensive results, or move long work to a background job so the request returns quickly.

Command

time curl -s -o /dev/null "https://example.com/slow-endpoint"

Shows how long the endpoint actually takes, so you can compare it to the proxy timeout.

How to confirm the fix: The endpoint responds well within the timeout, both cold and under normal load.

Prevent it from coming back

Set sane timeouts on every outbound call, index queries as data grows, and push slow tasks to a queue.