Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›HTTP Status Codes Reference›HTTP 504 Gateway Timeout
5xx Server Error

HTTP 504 Gateway Timeout

HTTP 504 Gateway Timeout means a gateway or proxy did not get a response from the upstream server in time. The backend is running but too slow, often because…

Quick answer

HTTP 504 Gateway Timeout means a gateway or proxy did not get a response from the upstream server in time. The backend is running but too slow, often because of long database queries, slow third-party APIs or a proxy timeout that is shorter than the work takes.

Last updated · Maintained by FreeAIToolz · How we test

What does HTTP 504 Gateway Timeout mean?

Each layer has its own timeout. Nginx proxy_read_timeout defaults to 60 seconds, AWS ALB idle timeout to 60 seconds, Cloudflare returns 524 after 100 seconds, and serverless functions have their own maximum duration.

Status code504
NameGateway Timeout
Class5xx Server Error
Defined inRFC 9110 §15.6.5
Cacheable by defaultNo, unless Cache-Control says so
Safe to retry automatically?Yes, with backoff

What causes HTTP 504?

  • Slow database queries or missing indexes.
  • Slow or hanging third-party API calls.
  • Proxy or load-balancer timeouts shorter than the request’s processing time.
  • Serverless function timeouts.

How do I fix HTTP 504?

  1. Profile and speed up the slow endpoint (indexes, caching, pagination).
  2. Add timeouts to outbound calls so they fail fast.
  3. Move long jobs to a background queue and return 202.
  4. Raise proxy timeouts only when the work legitimately takes longer.

What should a client do after HTTP 504?

Retry with backoff; consider a longer client timeout for known slow operations.

Does HTTP 504 affect SEO?

Slow responses reduce crawl rate; repeated 504s can lead to de-indexing. Aim for fast server responses (under about 600 ms TTFB).

Example 504 response

HTTP/1.1 504 Gateway Timeout
Date: Mon, 01 Dec 2026 12:00:00 GMT
Content-Type: application/json

{"error":{"status":504,"message":"Gateway Timeout"}}

How to return 504 Gateway Timeout in code

Express (Node.js)

res.status(504).json({ error: 'Gateway Timeout' });

Next.js route handler

return Response.json({ error: 'Gateway Timeout' }, { status: 504 });

FastAPI (Python)

raise HTTPException(status_code=504, detail="Gateway Timeout")

PHP

http_response_code(504);

Nginx

location = /example {
    return 504;
}

Other 5xx status codes

The server failed to fulfil a valid request. Retrying later, with backoff, is usually reasonable.

Frequently asked questions

504 vs 502?
504: the upstream was too slow. 502: the upstream returned an invalid response or refused the connection.
How do I increase the timeout in Nginx?
Set proxy_read_timeout (and proxy_connect_timeout / proxy_send_timeout) in the location block, then reload. Fix the slow code too.
Is 504 a client or server error?
504 is in the 5xx class, a server error: the request may be fine, but the server could not complete it.