504 Gateway Timeout: what it means and how to fix it

504 Gateway Timeout means a proxy or gateway (nginx, Cloudflare, a load balancer, an API gateway) forwarded the request to the server behind it and gave up waiting for a response. The connection worked, but the upstream was too slow. It may even finish the work after the client has already seen the error.

HTTP/1.1 504 Gateway Time-out
Server: nginx
Content-Type: text/html

<html><head><title>504 Gateway Time-out</title></head>
<body><center><h1>504 Gateway Time-out</h1></center><hr><center>nginx</center></body></html>

Common causes

  • A slow request. A heavy database query, a report, an export, or a call to a slow third-party API, all inside the request.
  • An overloaded upstream. Requests queue behind busy workers until they time out.
  • A stuck dependency. The app waits on a database lock, a hung connection or a downstream service with no timeout of its own.
  • Network problems between the proxy and the upstream: a firewall silently dropping packets, or a wrong IP that never answers.
  • Mismatched timeouts. A proxy with a 30-second timeout in front of a job that routinely takes 45.

How to fix it as a visitor

Wait and try again. If you were submitting something like a payment or a form, check whether it went through before resubmitting, because the server may have finished the work after the timeout.

How to fix it as a developer or ops

WhereWhat you seeDefault timeoutSetting
nginxupstream timed out (110: Connection timed out) while reading response header from upstream60sproxy_read_timeout, fastcgi_read_timeout for PHP-FPM
CloudflareError 524: A timeout occurred100sRaised only on Enterprise; otherwise make the origin respond faster
AWS ALB504 in access logs60s idle timeoutLoad balancer attribute idle_timeout.timeout_seconds
AWS API Gateway504 / Endpoint request timed out29s for REST integrationsIntegration timeout

Raising a timeout is fine when a request is legitimately long. More often, the real fix is in the app:

  1. Find the slow part. APM traces, slow query logs or timing logs around external calls.
  2. Move long work out of the request. Accept the job, return 202 Accepted with a job ID, and let the client poll or receive a webhook when it's done.
  3. Put timeouts on outbound calls, shorter than the proxy's, so the app can return a clean error instead of hanging.
  4. Add capacity if requests are timing out in a queue rather than in your code.

504s and timeouts on a webhook endpoint

Webhook senders wait only a short time for your response, usually a few seconds to a few tens of seconds. If your handler does the work inline (calls an API, writes several rows, sends an email), a slow moment turns into a timeout, the provider records a failure and retries. Your handler may have actually finished, so the retry becomes a duplicate.

The pattern that avoids it: verify the signature, store the raw event, return 200, process asynchronously. Then make processing idempotent so a retried delivery doesn't run twice.

If timeouts come from bursts, Webhook Relay throttling limits the rate or number of concurrent deliveries to your endpoint so it isn't flooded. And durable retries keep each event and retry with exponential backoff for up to 30 days, so a slow afternoon never loses data. For webhooks forwarded to localhost through relay forward, a provider reporting a timeout can also mean the agent couldn't reach your local server. See 502 Bad Gateway for that case.

When to return 504 from your own service

Return 504 only when your service is a gateway or proxy and the upstream it called didn't answer in time. If your own handler is slow, fix the handler or return 202 Accepted and finish the work in the background. For a timeout that happens because the client was too slow to send the request, the code is 408 Request Timeout.

Frequently asked questions

What does 504 Gateway Timeout mean?

A 504 Gateway Timeout means a proxy or gateway, such as nginx, Cloudflare or a load balancer, forwarded your request to the server behind it and didn't get a response in time. The upstream may still be working on the request; the proxy just stopped waiting.

How do I fix 504 Gateway Timeout in nginx?

The nginx error log shows upstream timed out while reading response header from upstream. Either make the upstream respond faster, or raise proxy_read_timeout, which defaults to 60 seconds, for the location that needs it. For PHP-FPM use fastcgi_read_timeout. Raising timeouts treats the symptom; slow requests usually need to become background jobs.

What is the difference between 502 and 504?

A 502 means the proxy got a bad response or none, for example because the app refused the connection or crashed. A 504 means the proxy connected and waited, but the app didn't answer before the timeout.

What is Cloudflare error 524?

Error 524 means Cloudflare connected to your origin but the origin didn't send an HTTP response within Cloudflare's timeout, 100 seconds by default. It's Cloudflare's version of a gateway timeout. Move long work out of the request or serve it from a path that responds quickly.

How do I stop webhook timeouts?

Respond quickly. Verify the signature, store the raw event, return 200, and do the slow work from a background queue. Providers usually wait only a few seconds to a few tens of seconds before counting a delivery as failed.