Key takeaways
- A 504 means something upstream is slow, usually a database query or external API.
- Bypass the CDN to tell whether the origin is at fault.
- Fix slow code and add caching before raising timeouts.
A 504 Gateway Timeout is returned by a proxy, CDN or web server when the server behind it doesn’t respond within the allowed time. Something is slow, not broken — and the fix is to find what.
Find the slow layer
- Reproduce it. Note which URLs time out. If it’s every page, suspect the server or database; if it’s one page, suspect that page’s code.
- Bypass the CDN. If the origin also hangs, the problem is on your server. If the origin is fast, check the CDN’s connection to your origin.
- Check the database. Slow queries are the most common cause. On WordPress, a plugin like Query Monitor shows queries per page; on a VPS, enable MySQL’s slow query log.
- Check external calls. Code that waits for a third-party API, payment gateway or font server can hang until the timeout.
Fix the cause, then the timeout
- Optimise or index slow queries, and remove plugins that run heavy queries on every page load.
- Move long jobs (imports, exports, image processing) to background tasks or cron jobs.
- Add page and object caching so most requests skip the slow path.
Only after that, if a legitimate request genuinely needs longer, raise the timeouts consistently across layers (for example Nginx proxy_read_timeout and PHP max_execution_time). Raising timeouts alone just makes visitors wait longer.