504 Gateway Timeout Error

Category: Errors & Troubleshooting ยท Updated 2026-11-05

A 504 Gateway Timeout is an HTTP status code meaning a server acting as a proxy or gateway did not get a response from the backend server it was waiting on, within the time it was willing to wait. It points to a slow or unresponsive backend, not a problem with the visitor's own connection.

What a 504 error means

A 504 belongs to the 5xx family of server-side errors. It specifically appears when one server is acting as a gateway or proxy, such as Nginx or Cloudflare sitting in front of an application server, and that proxy's wait for a response from the backend exceeds its configured timeout. It differs from related errors in a specific way:

  • 502 Bad Gateway โ€” the proxy got a response from the backend, but it was invalid or malformed.
  • 503 Service Unavailable โ€” the server is deliberately refusing requests, often due to overload or maintenance.
  • 504 Gateway Timeout โ€” the proxy received no response at all within the time allowed.

Common causes

  • A slow database query or a runaway script that takes too long to finish.
  • A traffic spike overwhelming the application server or PHP worker pool.
  • A backend server that crashed, restarted, or ran out of memory mid-request.
  • A firewall or security group silently dropping traffic between the proxy and the backend.
  • DNS or network issues between a CDN/proxy and the origin server.
  • A proxy timeout set too low for a legitimately slow but working operation, such as a large file export or report generation.

How to fix a 504 error

  1. Check server resource usage (CPU, memory, database connections) for signs of overload at the time of the error.
  2. Review slow query logs and optimize or add indexes to queries that take unusually long.
  3. Check application and web server error logs for the specific request that timed out.
  4. Increase proxy timeout settings if the operation is legitimately slow but working, for example in Nginx: proxy_read_timeout 120s;
  5. Confirm connectivity between proxy and origin, including firewall rules, if you use a CDN or reverse proxy like Cloudflare in front of your server.
  6. Restart or scale the backend if it has become unresponsive or undersized for current traffic.
# Example: raising Nginx proxy timeouts
location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_connect_timeout 60s;
    proxy_read_timeout 120s;
    proxy_send_timeout 120s;
}

Is a 504 error my fault as a visitor?

No. A 504 is a server-side problem between a proxy and a backend, not something caused by a visitor's browser, device or home connection. Reloading the page after a short wait sometimes works if the backend recovers, but the underlying fix has to happen on the server side.

Frequently asked questions

What does a 504 Gateway Timeout error mean?

It means a proxy or gateway server was waiting for a response from a backend server and gave up because no response arrived in time. The backend may be slow, overloaded, or unreachable.

What is the difference between a 502 and a 504 error?

A 502 means the proxy got a response from the backend but it was invalid, while a 504 means the proxy received no response at all within its timeout period.

How do I fix a 504 error on my own website?

Check for slow database queries, server overload, or crashed backend processes, and review your proxy's timeout settings. Increasing the timeout only helps if the backend will eventually respond; if it never will, the real fix is optimizing or scaling the backend.

Can a CDN like Cloudflare cause a 504 error?

Yes, if the connection or response time between the CDN and your origin server exceeds the CDN's gateway timeout. This can be caused by a slow origin server, a firewall blocking the CDN's IP ranges, or network issues between the two.

Does clearing my browser cache fix a 504 error?

No. A 504 is generated by servers, not stored or cached by your browser, so clearing cache or cookies will not resolve it. The fix has to happen on the server or proxy side.

Will refreshing the page fix a 504 error?

Sometimes, if the backend was only temporarily overloaded or restarting and has since recovered. If the problem is a persistently slow query or a crashed service, refreshing will keep producing the same error until the underlying issue is fixed.

Related topics