504 Gateway Timeout

A proxy or CDN waited too long for the server behind it.

Code
504
Reason phrase
Gateway Timeout
Class
5xx Server error
Defined in
RFC 9110 section 15.6.5
Cacheable by default
No

What it means

Server error: the request may be fine, but the server failed to carry it out.

When a server should send it. By a gateway or proxy when the server behind it did not answer in time. nginx's proxy_read_timeout and fastcgi_read_timeout default to 60 seconds.

Common causes. Slow database queries, long running scripts or an overloaded backend.

What to do. Retry. Site owners should find the slow request; raising the proxy timeout only hides it.

How clients and crawlers treat it

Browsers and HTTP clients. Browsers show the proxy's error page. The request may still be running on the backend, so a retried POST can run twice.

Google Search. Googlebot treats 5xx responses as a sign of trouble and temporarily slows its crawl rate. Already indexed URLs are kept at first, but are dropped if the errors continue. Source: Google Search Central, How HTTP status codes, and network and DNS errors affect Google Search.

Caching. Not cacheable by default (RFC 9110 section 15.1 does not list it). A cache stores it only when the response says so with Cache-Control or Expires.

Example response

HTTP/1.1 504 Gateway Timeout
Content-Type: text/plain; charset=utf-8

Gateway Timeout

How to send 504

nginx
location /example {
    return 504;
}
Apache (.htaccess)
RewriteEngine On
RewriteRule ^example$ - [R=504,L]
PHP
http_response_code(504);
echo 'Gateway Timeout';
exit;
Node.js
res.writeHead(504, { 'Content-Type': 'text/plain' });
res.end('Gateway Timeout');
Python (Flask)
# in a view function
return 'Gateway Timeout', 504

Change the paths to suit. In nginx, add_header needs always to apply to error responses.

Related codes

All status codes · All 5xx codes

Names and numbers from the IANA HTTP Status Code Registry. Google Search behaviour as documented by Google Search Central.