504 Gateway Timeout
HTTP response status code 504 Gateway Timeout is a server error indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
Usage
The 504 Gateway Timeout status code means the server is acting as a proxy or gateway for an upstream server. After receiving the HTTP request, the server attempted to forward the request to the upstream server but received no response within the allowed time.
This is related to the 502 Bad Gateway status code. A 502 indicates the upstream server returned an invalid response, while a 504 indicates no response was received at all.
Platform-specific timeouts vary. The Shopify API enforces a 10-second request timeout and returns 504 Gateway Timeout when a response is not ready within the window. Developers working with the Shopify API must optimize queries and use background processing for operations exceeding this limit.
SEO impact
Googlebot treats
5xx errors as a
signal to temporarily reduce the crawl rate
across the site. Previously indexed URLs are
preserved initially, but extended downtime
causes Google to drop them from the index. Any
content returned with a 504 response is
ignored. Google explicitly groups 500,
502, and 503 together as server errors
in its documentation. A 504 is not
explicitly included in the grouping but is
likely treated similarly as a general
5xx error. A
5xx error on the
robots.txt file is far more severe, even
when every other page on the site returns
200. Google halts crawling for up to 12
hours, then falls back to a cached copy for up
to 30 days. If the error persists, Google
fully deindexes the site.
Bingbot also treats
5xx responses as
crawl failures. Persistent
5xx errors prevent
indexing in Bing.
Example
The client requests a resource and the server responds with a 504 Gateway Timeout status code because the upstream server did not return an HTTP response.
Request
GET /news HTTP/1.1
Host: www.example.re
Response
HTTP/1.1 504 Gateway Timeout
Content-Type: text/html; charset=UTF-8
Content-Length: 128
<html>
<head>
<title>Gateway Timeout</title>
</head>
<body>
<p>The server is not responding.</p>
</body>
</html>
How to fix
The proxy timed out waiting for the backend to respond. The fix is either raising the timeout or making the backend faster.
Increase proxy timeouts.
In nginx, the default timeout is 60 seconds. Raise
the relevant directives in the server or
location block:
proxy_read_timeout 300;for reverse proxy setups usingproxy_passfastcgi_read_timeout 300;for PHP-FPM setups usingfastcgi_passproxy_connect_timeout 60;andproxy_send_timeout 300;also warrant review
In Apache, set ProxyTimeout 300 in the virtual
host or global configuration. When using
mod_proxy_fcgi, the timeout parameter on the
ProxyPassMatch directive controls the wait.
Align backend timeouts. The backend process
needs a matching or higher timeout. For PHP, raise
max_execution_time in php.ini and
request_terminate_timeout in the PHP-FPM pool
configuration. For Node.js, set server.timeout.
For Gunicorn, use --timeout.
Optimize the slow backend operation. A timeout is a symptom of a slow operation. Profile the request to find the bottleneck:
- Slow database queries: add indexes, reduce result sets, or move heavy work to a background job queue
- External API calls: add timeouts and circuit breakers so a stalled third-party service does not block the entire request
- Large file processing: stream the response instead of buffering the entire result
Respect platform-imposed timeouts. Hosted platforms enforce hard limits shorter than typical proxy defaults. Shopify imposes a 10-second ceiling. For operations exceeding the platform limit, offload work to background jobs and poll for results instead of blocking the HTTP request.
Check network path. Verify connectivity between
the proxy and backend with curl or telnet.
Packet loss, DNS delays, or firewall rules on
intermediate hops all contribute to timeouts. Run
traceroute to identify slow network segments.
Add Caching. For idempotent requests,
Caching the response at the proxy layer avoids
repeated slow backend calls. Nginx
proxy_cache_path and Apache mod_cache both
reduce upstream load.
Code references
.NET
HttpStatusCode.GatewayTimeout
Rust
http::StatusCode::GATEWAY_TIMEOUT
Rails
:gateway_timeout
Go
http.StatusGatewayTimeout
Symfony
Response::HTTP_GATEWAY_TIMEOUT
Python3.5+
http.HTTPStatus.GATEWAY_TIMEOUT
Java
java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_GATEWAY_TIMEOUT
Angular
@angular/common/http/HttpStatusCode.GatewayTimeout
Takeaway
The 504 Gateway Timeout status code is a server error indicating an upstream server did not respond in time and the HTTP request was not completed.
See also
- RFC 9110: HTTP Semantics
- Google: HTTP status codes and network errors
- 502 Bad Gateway
- 503 Service Unavailable
- 500 Internal Server Error
- HTTP status codes