A 504 Gateway Timeout error means a reverse proxy or load balancer (such as Nginx, Cloudflare, or an AWS load balancer) made a request to the origin server on your behalf and did not receive a response within its configured timeout period. The gateway received your browser’s request, forwarded it to the backend server, and then waited too long without getting a reply. The error is returned to you by the gateway, not the origin server itself, which is why it is called a Gateway Timeout rather than a server timeout.
This is a server-side error in nearly all cases. Your browser and connection are working correctly. The problem is between the proxy/CDN and the origin web server. For site visitors, the options are limited to waiting, retrying, or checking the site’s status. For site administrators, the 504 points to specific backend problems: PHP script execution time, database query performance, server resource limits, or misconfigured proxy timeout values.
What Causes a 504 Gateway Timeout
The most common cause is a PHP script or database query that takes longer to execute than the proxy’s timeout value allows. Nginx’s default proxy_read_timeout is 60 seconds. Cloudflare’s origin read timeout is 100 seconds on free plans. When a WordPress page with complex queries, heavy plugins, or inadequate server resources takes more than 60-100 seconds to generate a response, the gateway times out before the response arrives.
Server overload is the second major cause. When a server receives more simultaneous requests than its PHP-FPM worker count or Apache MaxRequestWorkers setting can handle, new requests queue behind the active ones. If the queue waits long enough, the gateway’s timeout expires before the request is dequeued and processed. This typically manifests as 504 errors during traffic spikes, major product launches, or viral content events.
Network issues between the gateway and origin server add a third failure mode. If the origin server’s IP changed (due to a migration or DNS update) and the load balancer has not been updated, or if there is a packet loss issue on the internal network between the CDN edge node and the origin, the gateway cannot establish or maintain a connection to the origin and returns 504 to the visitor.
Refresh the Page and Wait
Many 504 errors are transient. A server processes a heavy request, recovers, and subsequent requests succeed. Press Ctrl+F5 for a hard refresh that bypasses your browser cache and requests fresh content. Wait 30 seconds between refresh attempts to give the server time to process the current request queue. Hammering the refresh key sends more requests to an already overloaded server and prolongs the recovery time.
If the error appeared suddenly and the site was working minutes ago, a temporary traffic spike or a scheduled background task (database backup, plugin update, scheduled script) may be consuming server resources. Most transient 504 errors resolve within 2-5 minutes without any intervention from visitors or administrators.
Clear Browser Cache
Chrome may have cached a 504 error response and continues serving it from cache even after the server recovers. Press Ctrl+Shift+Delete, select All time, check Cached images and files, and click Clear data. Reload the page. If it loads after clearing the cache, Chrome was serving a cached error response, not a live one from the server.
This is particularly common when a CDN like Cloudflare caches error responses. Cloudflare does not cache 504 responses by default, but some custom caching rules or page rules can cause error caching. If you manage the site, check your CDN’s caching rules to ensure error status codes are not being cached.
Check Server Status
Use downforeveryoneorjustme.com to verify whether the 504 affects all visitors or just you. If the site is down for everyone, the origin server needs attention from its administrator. Check the site’s official social media accounts or status page (often at status.sitename.com) for outage announcements. Sites running on cloud infrastructure from AWS, Google Cloud, or Microsoft Azure typically post incident reports on their platform status pages.
If the site is up for others but you consistently receive 504, the issue may be geographic: the CDN edge node closest to you may have connectivity issues to the origin. Testing through a VPN or mobile hotspot reroutes your traffic through a different CDN edge node and can bypass a location-specific gateway problem.
Try a Different Browser or Device
Load the URL in Microsoft Edge, Firefox, or on your smartphone. If the page loads elsewhere but not in Chrome, Chrome-specific settings (a proxy extension, a cached bad response, or an extension that adds request headers) are interfering. Disable all Chrome extensions, clear cache, and test in incognito mode. If it fails in all browsers on the same network, the issue is definitively server-side or network-side between you and the server.
For Site Administrators: Fix the Origin Server
A 504 Gateway Timeout on your own site requires backend investigation. Start by checking your server’s error logs. For Nginx, check /var/log/nginx/error.log. For Apache, check /var/log/apache2/error.log. For PHP-FPM, check its pool log. The logs show whether PHP processes are timing out, whether the database is slow, or whether the server is out of memory.
The most common PHP-level fix is increasing max_execution_time in php.ini (default is 30 seconds; increase to 300 for complex operations) and max_input_time. For Nginx reverse proxy, increase proxy_read_timeout in your server block to match your application’s expected execution time. For MySQL/MariaDB, identify slow queries using the slow query log (set long_query_time = 2 in my.cnf) and optimize or add indexes to the slowest queries.
Cloudflare-Specific 504 Fixes
Cloudflare’s Gateway Timeout occurs when Cloudflare cannot reach your origin server within 100 seconds (free plan) or 600 seconds (Enterprise plan). To fix it: ensure your origin server is accessible at the IP addresses configured in Cloudflare’s DNS settings, check that your origin server is not blocking Cloudflare’s IP ranges (listed at cloudflare.com/ips), and verify that your origin server’s SSL certificate is valid if you use Full or Full (Strict) SSL mode in Cloudflare.
Nginx and Apache Timeout Configuration
For Nginx acting as a reverse proxy, add these directives inside your location block: proxy_connect_timeout 60s; proxy_send_timeout 300s; proxy_read_timeout 300s; These set the timeout for connecting to the upstream server, sending the request, and reading the response separately. For Apache with mod_proxy, set ProxyTimeout 300 in your VirtualHost configuration.
Advanced Fix: Scale Server Resources
If 504 errors appear consistently under normal traffic, the origin server is undersized for its workload. Check server RAM usage: if it is consistently above 80%, pages cannot be fully generated in memory and disk swapping causes extreme slowness. Add more RAM or upgrade your hosting plan. Check PHP-FPM’s pm.max_children setting: if all workers are busy, new requests queue until a worker is free, causing gateway timeouts under concurrent load.
For WordPress sites, install a caching plugin (WP Rocket, W3 Total Cache, or LiteSpeed Cache) to serve static HTML pages for most visitors instead of generating PHP responses dynamically. This reduces server resource consumption by 70-90% for cached pages and eliminates the PHP execution time that triggers 504 errors.
Frequently Asked Questions
What is the difference between a 502 and 504 error?
A 502 Bad Gateway means the gateway received an invalid response from the origin server. A 504 Gateway Timeout means the gateway received no response at all within its timeout period. A 502 indicates the origin server responded but with something the gateway could not process. A 504 indicates the origin server did not respond at all, typically because it was overloaded, crashed, or unreachable from the gateway’s network.
How long should I wait before retrying a 504 error?
Wait 30-60 seconds before the first retry, then 2 minutes before the second. If the site is recovering from an overload event, rapid retries add to the server’s queue and extend recovery time. If the 504 persists for more than 10 minutes, the server has a more serious problem that requires administrator intervention. Use downforeveryoneorjustme.com to monitor whether the site recovers for other users.
Can a 504 error be caused by my internet connection?
Rarely. A 504 error is generated by the gateway server and returned to your browser as a valid HTTP response, which means your internet connection is working well enough to receive it. If your connection were completely broken, you would see ERR_CONNECTION_TIMED_OUT or ERR_NETWORK_CHANGED instead. A very slow connection can occasionally contribute to a 504 if the gateway’s read timeout expires while transferring your large request body, but this is uncommon for standard web browsing.
Why do I only get 504 errors at certain times of day?
Time-specific 504 errors indicate server overload during peak traffic periods or scheduled background tasks. Many hosting providers run automated backups, database optimization routines, or cron jobs at specific hours, consuming server resources that trigger 504 errors for concurrent visitors. On shared hosting, other sites on the same physical server consuming excess resources can also cause your site to exceed its resource allocation and return 504 errors during those periods.
For connection failures that occur before reaching the gateway, see the ERR_CONNECTION_REFUSED guide. If the connection times out before any response, the ERR_TIMED_OUT article covers that client-side timeout scenario. For rate limiting errors that appear alongside gateway timeouts under high load, the 429 Too Many Requests guide explains the server-side request throttling context.








