The gateway did not receive a timely response from the upstream server.
The server acting as a gateway or proxy did not receive a timely response from the upstream server it needed to access in order to complete the request. Simply put, the middleman server waited too long for the backend to respond and gave up.
A 504 Gateway Timeout error occurs when a reverse proxy or load balancer's timeout expires before the upstream server finishes processing a long-running request. The proxy has a configured maximum wait time, and if the backend doesn't respond within that window, the proxy returns a 504 to the client.
This is different from a 502: with a 502, the upstream sent a bad response. With a 504, the upstream sent no response at all within the allowed time. The operation may still be running on the backend -- it just took too long for the proxy's patience.
EXPLAIN plans, avoid SELECT *, and break complex queries into smaller ones. This is the most common root cause.proxy_read_timeout 300s in Nginx configuration. Only do this after optimizing -- increasing timeouts masks the real problem.ping and traceroute to identify network bottlenecks between your proxy and upstream servers.GET /api/reports/annual HTTP/1.1 Host: example.com Accept: application/json
HTTP/1.1 504 Gateway Timeout Content-Type: text/html Server: nginx/1.24.0 Date: Thu, 20 Feb 2026 12:00:00 GMT <html> <head><title>504 Gateway Time-out</title></head> <body><center><h1>504 Gateway Time-out</h1></center></body> </html>
proxy_read_timeout in Nginx) or switch to async processing with a job queue. For large file uploads, increase both client and proxy timeouts.Cache-Control, ETag) and use tools like Redis or Varnish for server-side caching.Monitor your website 24/7 and receive instant alerts when 504 errors occur.
Start Free Monitoring