HTTPQUERY
中文

504 Gateway Timeout

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.

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: example.com

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:

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:

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