What does HTTP 504 mean?
A gateway or proxy did not get a response from the upstream server in time. The application is reachable but too slow: the proxy gives up after its timeout (60 s by default in Nginx proxy_read_timeout; 100 s at Cloudflare; 10–60 s on serverless platforms).
5xx Server error: The request looked valid, but the server failed to fulfil it. The fix is on the server side.
Common causes of a 504 error
- Slow database queries or external API calls.
- Long-running requests such as reports or imports done synchronously.
- Serverless function time limits.
How to fix 504 Gateway Timeout
- Optimize slow queries and add caching.
- Move long tasks to background jobs and return 202.
- Raise proxy timeouts only as a last resort.
How to find the cause of a 504
A 504 means your app is too slow for the proxy’s time limit, so time the app directly.
curl -o /dev/null -s -w 'total: %{time_total}s\n' http://127.0.0.1:3000/slow-page
sudo tail -n 30 /var/log/nginx/error.logIf the direct request is slow, fix the slow query or outside call. Raising the limit, such as proxy_read_timeout 120s; in Nginx, only helps for work that is meant to take long. Move long jobs to the background instead.
504 and SEO
Slow responses hurt Core Web Vitals and crawling; persistent 504s cause deindexing like other 5xx errors.
Example response
HTTP/1.1 504 Gateway Timeout
How to return a 504 response
Node.js (Express)
res.status(504).json({ error: 'Gateway Timeout' });PHP
http_response_code(504);Python (Flask)
return {'error': 'Gateway Timeout'}, 504Go (net/http)
w.WriteHeader(504)nginx
return 504;
Related status codes
- 502 Bad Gateway — A gateway or proxy got an invalid response from the upstream server.
- 503 Service Unavailable — The server is temporarily unable to handle the request.
- 408 Request Timeout — The server timed out waiting for the client to send the request.
- 524 A Timeout Occurred — Cloudflare connected to the origin, but it did not send a response within 100 seconds.
Check which status code a URL returns with the HTTP header checker.