Back to all status codes
504

Gateway Timeout

The server acting as a gateway did not receive a timely response from the upstream server.

Common Causes

  • Slow database queries
  • Long-running processes
  • Network latency
  • Upstream server busy

Fix Solutions

Optimize backend

Improve slow database queries and optimize backend code.

Increase timeouts

Increase gateway timeout values to accommodate slow requests.

Use async processing

Move long-running tasks to background workers.

Code Examples

# Increase timeout for slow backends
location /api {
    proxy_pass http://backend;
    proxy_read_timeout 300s;
    proxy_connect_timeout 75s;
}

Related Tools