Skip to content
504

Gateway Timeout

Server Error (5xx)

The 504 Gateway Timeout status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server. This is a timeout issue between the proxy and the backend, not between the client and the proxy. The upstream server may be overloaded, slow, or unreachable.

What is HTTP 504 Gateway Timeout?

HTTP 504 Gateway Timeout is a server error (5xx) status code. The 504 Gateway Timeout status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server. This is a timeout issue between the proxy and the backend, not between the client and the proxy. The upstream server may be overloaded, slow, or unreachable. Common causes include upstream server taking too long to respond and database query timeout on the backend. To fix it, increase proxy timeout settings (proxy_read_timeout in nginx).

Example Response

HTTP/1.1 504 Gateway Timeout
Content-Type: text/html

<h1>504 Gateway Timeout</h1><p>The upstream server did not respond in time.</p>

Common Causes

How to Fix

  1. 1. Increase proxy timeout settings (proxy_read_timeout in nginx)
  2. 2. Optimize slow queries or operations on the upstream server
  3. 3. Check network connectivity between proxy and upstream
  4. 4. Add caching to reduce upstream server load
  5. 5. Consider asynchronous processing for long-running requests

Frequently Asked Questions

How do I increase nginx proxy timeout?

Add these to your nginx configuration: proxy_connect_timeout 60s; proxy_read_timeout 120s; proxy_send_timeout 60s. Adjust the values based on your application's response time requirements.

Is it safe to retry on 504?

It depends on the operation. GET requests are safe to retry. For POST, PUT, or DELETE, ensure the operation is idempotent before retrying, as the upstream may have received and started processing the request.

What is the difference between 504 and 408?

504 means the proxy timed out waiting for the backend server. 408 means the server timed out waiting for the client to finish sending the request. 504 is a backend issue; 408 is a client-side issue.

Related Status Codes

502 Bad Gateway 503 Service Unavailable 408 Request Timeout

Related Reading

HTTP Status Codes Cheat Sheet: Every Code Explained → JSON vs YAML vs TOML: Which Config Format to Use →