5xx Server Error
HTTP 504 Gateway Timeout
The server, while acting as a gateway or proxy, did not get a response in time from the upstream server. The backend took too long to respond, and the gateway gave up waiting.
Common Causes
- Backend server is too slow to respond
- Long-running database query or computation
- Network latency between proxy and backend
- Upstream server is deadlocked or hung
How to Fix
- 1Increase gateway/proxy timeout settings
- 2Optimize slow backend operations and database queries
- 3Add caching to reduce backend load
- 4Break long operations into async jobs returning 202
Example
HTTP 504 Gateway Timeout
GET /api/report HTTP/1.1 → Nginx (proxy, 30s timeout) → Backend takes 60s to generate report → 504 Gateway Timeout