504 Gateway Timeout
Gateway/proxy timeout waiting for upstream server.
The server did not receive a timely response from the upstream server.
What HTTP 504 Gateway Timeout Means
The server did not receive a timely response from the upstream server.
Gateway/proxy timeout waiting for upstream server.
Common Causes
- Upstream server too slow
- Database query timeout
- Slow application response
- Network latency
- Long-running script
How to Fix It (For Visitors)
- Refresh the page
- Try again later
- Contact website administrator
How to Fix It (For Developers/Admins)
- Increase gateway timeout (proxy_read_timeout)
- Optimize slow database queries
- Add indexes to database
- Implement caching
- Optimize application code
- Use async processing for long tasks
Timeouts at Each Layer
| Layer | Setting | Default |
|---|---|---|
| nginx reverse proxy | proxy_read_timeout | 60s |
| nginx + PHP-FPM | fastcgi_read_timeout | 60s |
| Apache mod_proxy | ProxyTimeout (falls back to Timeout) | 60s |
| AWS Application Load Balancer | Idle timeout | 60s |
| Cloudflare proxy | Proxy read timeout (shown as 524) | 100s |
Raising a timeout only hides the symptom. Find out why the upstream is slow (slow queries, locks, external API calls) and move long-running work to background jobs that the client can poll.
Returning a 504 Gateway Timeout (Code Examples)
If you build APIs or web apps, here is how to send an HTTP 504 response and how to test for it:
Node.js (Express)
app.get('/resource', (req, res) => {
res.status(504).json({ error: 'Gateway Timeout' });
});
Python (Flask)
@app.route('/resource')
def resource():
return jsonify(error='Gateway Timeout'), 504
PHP
<?php
http_response_code(504);
header('Content-Type: application/json');
echo json_encode(['error' => 'Gateway Timeout']);
Check the status with curl
curl -I https://example.com/resource
# Look for: HTTP/1.1 504 Gateway Timeout
Frequently Asked Questions
What does HTTP 504 Gateway Timeout mean?
Gateway/proxy timeout waiting for upstream server. In short: The server did not receive a timely response from the upstream server.
Is a 504 Gateway Timeout error my fault or the website's?
504 is a 5xx server-error code, so the problem is on the server side, not your browser or device. As a visitor you can usually only retry; if you run the site, investigate the server.
How do I fix a 504 Gateway Timeout error?
Increase gateway timeout (proxy_read_timeout). Optimize slow database queries. Add indexes to database.
Official Specification
The 504 Gateway Timeout status code is defined in RFC 9110 Section 15.6.5.