504 Gateway Timeout means a gateway or proxy did not get a response from the upstream server in time.
HTTP/1.1 504 Gateway TimeoutCommon causes
- A slow database query or external API call that keeps the application busy past the proxy's timeout.
- The upstream server is overloaded or unreachable.
- Timeouts that are shorter at the proxy than at the application.
How to fix it
- Find the slow request in the application logs and make it faster, or move it to a background job.
- Raise the proxy timeout (for example proxy_read_timeout in nginx) only if the work is legitimately long.
- For long operations, answer 202 Accepted and let the client poll.