504 Gateway Timeout

HTTP 504 status code means a proxy server (also known as gateway) didn’t receive the response from the upstream server (also known as application server) in a timely manner.

Having a proxy server in front of the application server is a common pattern in production web apps. Web servers are more efficient/capable in terminating TLS connections, dealing with slow clients, compressing requests, and serving static files quickly. Some popular web servers used as proxies are Apache, Nginx, and Caddy.

While you can increase a timeout on the web server, it is better to solve the underlying problem on the upstream server.

When proxying requests to the upstream server, make sure you send the following HTTP headers from the web server:

X-Forwarded-For
X-Forwarded-Host
X-Forwarded-Port
X-Forwarded-Proto
X-Real-Ip