Last tested: October 22, 2026 · By Alex
504 Gateway Timeout means a server acting as a gateway or proxy did not receive a response from the upstream server in time. The request reaches the gateway, but the backend service takes too long to respond. When the timeout limit is exceeded, the gateway stops waiting and returns a 504 error.
Quick Fix
- Reload the page after a few seconds.
- Check whether the upstream server is running.
- Restart the web server and application service.
- Review proxy timeout settings.
- Disable recently installed plugins or modules.
- Check server logs for slow queries or service failures.
What 504 Gateway Timeout Actually Means
Modern websites usually rely on several servers working together. A typical request might pass through a CDN or load balancer, a reverse proxy (like Nginx or Apache), an application server, and database or API services.
A 504 Gateway Timeout occurs when one of these components waits too long for a response from the next service in the chain. The gateway server is working fine, but the upstream service is simply too slow to reply.
Common Causes of 504 Gateway Timeout
Slow Backend Application
If the application takes too long to process requests, the gateway closes the connection and throws the timeout error.
Database Performance Issues
Long or unoptimized database queries are a frequent cause of delayed backend responses.
Server Resource Exhaustion
High traffic can consume CPU, memory, or worker processes. When resources are limited, response times increase and timeouts occur.
Network Connectivity Problems
Communication delays or firewall drops between internal servers can easily cause gateway timeouts.
Low Proxy Timeout Limits
If proxy timeout settings are too strict, legitimate requests may be terminated before the backend finishes processing them.
How to Fix 504 Gateway Timeout
Step 1 — Reload the Page
Temporary slowdowns sometimes resolve automatically. Wait a few seconds and reload the page before diving into server configurations.
Step 2 — Check Backend Server Status
Confirm the upstream server is running and accepting connections. If the gateway cannot reach the backend service (for example PHP-FPM or Node.js), requests will fail.
Step 3 — Restart Web Services
Restarting services often restores communication between layers and clears stalled worker processes.
sudo systemctl restart nginx
sudo systemctl restart apache2If your application runs separately (like a Node or Python app), restart that service as well.
Step 4 — Review Server Logs
Logs usually reveal the exact source of the delay. Check your Nginx or Apache error logs, application server logs, and database logs. Look for slow queries, connection failures, or service crashes.
Step 5 — Disable Recent Changes
If the error appeared after installing plugins or deploying new code, revert the change. Resource-heavy plugins or bad loops in code are common causes of slow responses.
Step 6 — Adjust Proxy Timeout Settings
If legitimate requests (like large file uploads or complex reports) take longer to process, increase your timeout limits. Here is an example Nginx configuration to increase timeouts to 60 seconds:
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;Advanced Troubleshooting
Check Database Query Performance
Slow database queries are one of the most common causes of backend delays. Use slow query logs to identify and optimize them.
Inspect Load Balancer Health Checks
Load balancers may mark backend nodes as unavailable when response times exceed thresholds, triggering 504 errors across the board.
Monitor Server Metrics
High CPU or memory usage often indicates bottlenecks. Use monitoring tools to pinpoint resource exhaustion.
Review External API Dependencies
If the application relies on third-party APIs, slow external responses can propagate through your system and cause your own gateway to time out.
Does 504 Gateway Timeout Affect SEO?
Short outages usually do not impact rankings, as search engines treat 504 responses as temporary server problems. However, repeated timeouts may reduce your crawl budget and negatively affect your search visibility over time.
Prevention Best Practices
- Monitor server performance metrics proactively.
- Use object caching (like Redis or Memcached) to reduce backend load.
- Optimize database queries and index your tables.
- Scale infrastructure automatically during traffic spikes.
- Regularly update server software and application dependencies.
When to Contact Support
Contact your hosting provider if 504 errors occur frequently, backend servers respond slowly without a clear cause, or if you are on shared hosting and cannot adjust proxy timeout limits yourself. Provide them with exact timestamps and error logs to speed up the fix.
Upstream Request Timeout and “upstream timed out” Errors
Many visitors never see the words “504 Gateway Timeout” at all. Depending on the software sitting in front of the application, the same failure can show up as a plain-text upstream request timeout message, a Cloudflare error page, or a line in the Nginx error log. They all describe one situation: a proxy forwarded the request, waited for the backend, and gave up before an answer came back.
Where these messages come from
- Nginx – the browser gets a 504 page, while
error.logrecords something likeupstream timed out (110: Connection timed out) while reading response header from upstream. Error 110 is the Linux code for a connection timeout. - Envoy, Istio and Kubernetes ingress – the response body is often just
upstream request timeout. Envoy’s default route timeout is 15 seconds, so slow API calls hit it quickly. - Cloudflare – if your origin accepts the connection but takes longer than about 100 seconds to reply, Cloudflare shows Error 524 instead of a generic 504.
- Load balancers (AWS ALB, HAProxy) – they return 504 when the idle or server timeout expires before the target answers.
Read the log line before changing anything
The exact wording of the Nginx message tells you which stage stalled:
while connecting to upstream– the backend is down, unreachable, or refusing new connections. Raising read timeouts will not help; check that the service is running and the port is correct.while reading response header from upstream– the backend accepted the request but is too slow to produce a response. This is the most common case and points to slow PHP, database queries, or external APIs.while sending request to upstream– usually a large upload or a backend that has stopped reading its input.
sudo tail -f /var/log/nginx/error.log | grep "upstream timed out"Matching timeouts for PHP and proxied backends
Nginx uses different directives depending on how it talks to the backend. For a reverse proxy (Node.js, Apache, a container) adjust the proxy_* values; for PHP-FPM, which is what most WordPress hosts run, the fastcgi_* values apply instead:
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_connect_timeout 60s;
fastcgi_read_timeout 120s;
fastcgi_send_timeout 120s;
}A higher Nginx limit is useless if PHP kills the script first. Keep these values in step with each other:
; php.ini
max_execution_time = 120
; PHP-FPM pool (www.conf)
request_terminate_timeout = 120sOn Kubernetes with the NGINX Ingress Controller, the same idea is set through annotations:
nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
nginx.ingress.kubernetes.io/proxy-send-timeout: "120"For Envoy or Istio, raise the timeout field on the route or VirtualService (for example timeout: 60s).
Treat longer timeouts as a stopgap
Increasing limits buys time for legitimately slow jobs such as imports, backups, or report generation. If ordinary page loads need more than a few seconds, the real fix is upstream: cache pages, add database indexes, move heavy tasks to a background queue or WP-Cron, and add more PHP-FPM workers if every worker is busy. Check pm.max_children warnings in the PHP-FPM log. When all workers are busy, new requests sit in the queue until the proxy timeout runs out.
Frequently Asked Questions
A proxy or gateway waited too long for a response from the upstream server and gave up.
502 means the upstream returned an invalid response; 504 means it did not respond in time.
Only as a short-term fix. Find the slow part first, such as a heavy database query or an external API call.
No. It usually indicates a temporary delay or overload in backend processing.
Yes. Heavy load can exhaust server resources, slowing down backend services and triggering proxy timeouts.
Most cases are resolved within minutes once the slow backend service or unoptimized query is identified.
It means a proxy such as Envoy, Istio, Nginx, or a load balancer forwarded your request to a backend service, and the backend did not reply within the allowed time. It is the same failure as a 504 Gateway Timeout, shown with different wording. Speed up the backend, or raise the route timeout if the operation really does take long.
First check where it happened. “While connecting” means the backend is down or unreachable. “While reading response header” means the backend is too slow. For the slow case, raise proxy_read_timeout (or fastcgi_read_timeout for PHP-FPM) and keep PHP’s max_execution_time in line with it, then reload Nginx. Long term, fix the slow queries or the plugins causing the delay.
Final Thoughts
504 Gateway Timeout indicates that a gateway server waited too long for a response from an upstream service. The most common causes are slow backend applications, heavy traffic, or database performance issues. Identifying the slow component and optimizing response times or adjusting timeout limits usually resolves the problem permanently.
Related Server Errors
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- Cloudflare Error 524
- Cloudflare Error 522
Hi, I’m Alex — the person behind ErrorRescue.
I’ve been working with websites, servers, and hosting for over 8 years. Most of my experience comes from troubleshooting real problems on WordPress sites, VPS and shared hosting environments, and Cloudflare setups. I’ve dealt with everything from SSL certificate failures and DNS misconfigurations to 504 timeouts, memory exhaustion errors, and Cloudflare 5xx issues.
I started ErrorRescue because I got tired of seeing generic, outdated, or incomplete error guides. My goal is to write clear, practical fixes based on what actually works in production — not just theory. Every guide here is tested against common server setups (Apache, NGINX, Cloudflare, and popular WordPress stacks).
When I’m not fixing sites, I’m usually reviewing new hosting configurations or updating existing guides so they stay accurate.