Web Hosting

Fix "504 Gateway Timeout" on Your Website

504 Gateway Timeoutupstream timed outrequest took too long
5 min read Updated 12 June 2026 ESAGAMES Team

A 504 means nginx waited for the backend and it didn't answer in time. Unlike a 502 (bad response), a 504 is purely about slowness. Here's how to fix it.

Cause 1: a slow script or query

The usual cause — a long-running PHP script or a slow database query exceeds the proxy timeout. Find it in the slow log and optimise it (add an index, cache the result, or move heavy work to a background job).

Cause 2: the backend is overloaded

If PHP-FPM has too few workers for the traffic, requests queue and time out. Raise pm.max_children sensibly (watch RAM) so requests aren't waiting in line.

Cause 3: timeout set too low

If the work is legitimately long (an import, a report), raise the timeout — but treat that as a last resort, not a fix for slow code:

# nginx
fastcgi_read_timeout 120s;
proxy_read_timeout 120s;
Raising the timeout hides the cause

A 504 is a symptom of something slow. Bumping the timeout stops the error but the request is still slow for users. Optimise the script/query first.

504 = too slow. Find the slow script/query and fix it; add FPM workers; only raise timeouts as a last resort.

Fast NVMe web hosting

Our web hosting runs on fast NVMe and tuned PHP-FPM, so slow timeouts are rare — DDoS protection included.

See web hosting
FAQ

Frequently asked questions

What does 504 Gateway Timeout mean?

Nginx forwarded the request to the backend but didn't get a response within the timeout. The backend (a PHP script, a query, an app) is too slow or overloaded.

How do I fix a 504 error?

Find and optimise the slow script or database query, add more PHP-FPM workers if requests are queuing, and only raise the proxy/FPM timeout as a last resort for genuinely long tasks.

Is 504 the same as 502?

No. 504 means the backend was too slow (timed out); 502 means it returned a bad or empty response (often crashed). Different causes, different fixes.

Knowledge base

Related articles

Skip the troubleshooting

Managed, protected hosting in Frankfurt — we handle the Linux, the network and the DDoS so you don't have to.

Payments Secure checkout with cards, banking apps and digital wallets.

Choose the payment flow that fits your stack and region without leaving the platform.

Pay by Zen Visa Mastercard Paysafecard PaysafeCash Skrill Trustly Bancontact UnionPay iDeal WebMoney