How to fix the 504 Gateway Timeout error

How to fix the 504 Gateway Timeout error

The 504 Gateway Timeout error happens when the main server can’t get a response from another server that it needs to complete a request.

Causes of a 504 error often point to issues with the upstream server, such as it being overloaded, malfunctioning, or simply down. These issues prevent the gateway server from successfully processing the user’s request, leading to the timeout.

These issues can range from temporary glitches to more complex server configurations. Therefore, fixing a 504 Gateway Timeout error may require checking different parts of your website, from simple client-side issues to deeper server problems.

Here are eleven methods to resolve a 504 Gateway Timeout error:

  1. Refresh the page. The error can be temporary. Reloading ensures the browser makes a fresh request to the server.
  2. Try a different browser. This rules out issues caused by browser settings, cache, or extensions that might interrupt the connection.
  3. Check your proxy server settings. Incorrect or overloaded proxy settings can delay communication with the server, leading to timeouts.
  4. Disable your firewall. An overly strict firewall may block requests or slow down connections, preventing the server from responding in time.
  5. Flush your DNS cache. Outdated or corrupted DNS cache can misroute requests. Flushing it forces your computer to fetch fresh server details.
  6. Check your website’s error log. Error logs can reveal specific server-side issues or bottlenecks causing the timeout.
  7. Check your website’s plugins. Faulty or poorly optimized plugins can increase server response times, triggering a timeout error.
  8. Disable your CDN. A misconfigured or overloaded CDN might not deliver responses correctly; disabling it helps test if that’s the cause.
  9. Check your server resources. Insufficient memory, CPU, or bandwidth on your server can prevent it from handling requests promptly.
  10. Configure your Apache and NGINX settings. Incorrect timeout or proxy settings in these web servers can cause delays that trigger 504 errors.
  11. Contact your hosting provider’s customer support. If the issue is beyond your control, support can check network routes, server load, or data center issues.

The eleven methods in our troubleshooting guide cover both simple browser fixes and server-related solutions. While these solutions work for most websites, we’ll also include specific steps for WordPress users.

Continue reading to learn how to do each method, starting with simple client-side checks and moving toward more advanced server-side solutions.

1. Refresh the page

Refreshing the web page is often the first and simplest step in resolving a 504 Gateway Timeout error. This action can fix temporary connectivity issues, especially if the error is due to a momentary glitch or server overload.

Make sure to clear your browser’s cache and web cookies before refreshing to solve potential underlying issues. To refresh the page, click the Reload button in your browser. Alternatively, you can use keyboard shortcuts. Press CTRL+R on Windows or COMMAND+R if you’re using macOS.

Do note that refreshing web pages won’t solve the error if the server is still experiencing ongoing issues. In such cases, further troubleshooting of 504 Gateway Timeout methods is necessary.

2. Try a different browser

Switching to a different web browser can single out whether a 504 Gateway Timeout error is specific to the browser you’re using. Issues such as outdated software, third-party extensions, or a corrupted browser cache can cause such an error.

Try opening another web browser on your device and accessing the same web page. Alternatively, use incognito mode in your current browser.

If the web page loads successfully, the issue may lie with your primary browser’s cache, extensions, or settings.

In case the page still doesn’t load, it could indicate a more widespread issue, possibly on the server-side. You can check if the website is down for others by using an online service like Website Planet or Site24x7.

3. Check your proxy server settings

A proxy server sits between your device and the internet, offering privacy benefits like hiding your device’s location or encrypting web requests. Incorrect proxy settings may hinder proper communication with web servers, though that scenario is uncommon.

Here are steps to check your computer’s proxy settings:

Windows 11

  1. Go to Settings → Network & Internet → Proxy. You’ll find options like Automatically detect settings and Use a proxy server.
Accessing the Proxy menu on Windows 11
  1. If Use a proxy server is enabled, ensure the address and port details are correctly set for your network.
  2. Alternatively, turn off this option and then try reaccessing the website.

macOS Sonoma

  1. Click the Apple icon and select System Settings → Network.
  2. Next to your connected network service, click Details.
  3. Select the Proxies tab. Disable all proxy options by toggling off each proxy-related setting.
Accessing the Proxies tab on macOS Sonoma

Although some computers and networks don’t use proxy services by default, web browsers may have separate proxy configuration settings. Therefore, it’s advisable to check that as well.

Important! Remember that altering your network settings can impact your entire internet access, causing potential problems of its own. Pay close attention when making any changes to your network settings.

4. Disable your firewall

A firewall is an essential tool to safeguard your computer against unauthorized access and various cyber threats. However, a faulty firewall configuration may mistakenly prevent legitimate network requests, leading to the 504 Gateway Timeout error.

Follow these steps to turn off your firewall temporarily:

Windows 11

  1. Click the Start menu and select Settings.
  2. Go to Privacy & Security → Windows Security → Firewall & Network Protection.
Accessing the Firewall & network protection tab on Windows 11
  1. Choose your currently active network (for example, Private, Public, or Domain network) and turn off Microsoft Defender Firewall.

macOS Sonoma

  1. Open System Settings → Network.
  2. Scroll down and select Firewall.
  3. Click the toggle button to turn off the firewall.
Turning off Firewall on macOS Sonoma

After turning off the firewall, try reaccessing the website to determine if faulty firewall settings were contributing to the 504 error.

Important! Deactivating your firewall should be a temporary troubleshooting step. It is generally not recommended to leave your firewall disabled, as this can significantly increase the vulnerability of your system.

5. Flush your DNS cache

Flushing the DNS cache can be effective in resolving network connectivity issues, such as 504 Gateway Timeout errors. This process clears outdated or corrupted DNS information that might prevent your device from connecting to websites.

To fix client-side DNS issues, try flushing your DNS cache in your operating system:

Windows 11

  1. Search for cmd in the taskbar and right-click Command Prompt → Run as administrator.
  2. Type ipconfig /flushdns and hit Enter.
  3. A message will appear to confirm a successful flush of the DNS resolver cache.
Running the flush DNS cache command on Windows' Command Prompt

macOS Sonoma

  1. Open Terminal from Applications → Utilities.
  2. Type sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder and hit Enter.
  3. Enter your administrator password if prompted.

Google Chrome

Google Chrome maintains a separate DNS cache. To clear it:

  1. Start Chrome, then type chrome://net-internals/#dns in the address bar and press Enter.
  2. Click the Clear host cache button to flush Chrome’s DNS cache.
Selecting the Clear host cache button on Google Chrome

If your website has recently moved to a different IP address or server, you might need to wait up to 48 hours for the DNS propagation process to complete since ISPs need to update their records.

Use tools like whatsmydns.net to verify whether the propagation is complete.

For persistent DNS issues, switch to a public DNS service like Google Public DNS, Cloudflare 1.1.1.1, or Quad9 for faster and more reliable DNS resolution.

6. Check your website’s error log

One of the causes of the 504 Gateway Timeout can be code corruption from recent updates or third-party plugins. Checking the website’s error log may help identify this problem. Error logs record various issues that occur on your site, including those leading to a 504 error code.

Hostinger’s web hosting customers can utilize the PHP error logging feature through the hPanel. Here’s how:

  1. Log in to hPanel and navigate to Advanced → PHP Configuration.
  2. In the PHP options tab, check the logErrors box.
Selecting the logErrors box under the PHP options tab on hPanel
  1. Scroll down and click Save to activate PHP error logging.
Hostinger web hosting banner

If your hosting provider doesn’t offer PHP error logging by default and you use WordPress, you can enable the debug mode on your site by following these steps:

  1. Open your default File Manager application and find the wp-config.php file.
  2. Add the following lines to the file right before the /* That’s all, stop editing! Happy publishing. */ line:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Adding codes to enable debug mode on a WordPress website
  1. Save your changes before exiting.

Here are the explanations of each variable:

  • WP_DEBUG. Enables WordPress debug mode.
  • WP_DEBUG_LOG. Saves all PHP errors in the wp-content/debug.log file.
  • WP_DEBUG_DISPLAY. Decides if debug messages will be shown on HTML pages. Setting it to false hides errors on the site but still logs them within the file.

After changing these settings, you can access raw WordPress error log files via SFTP. They are usually located in the server’s root directory under the logs folder.

Furthermore, checking the server log files is also helpful for troubleshooting. Here are some typical locations for server logs, depending on the web server used:

  • Apache. The error log is usually found in /var/log/apache2/error.log/.
  • NGINX. For NGINX servers, check /var/log/nginx/error.log/.

7. Check your website’s plugins

In rare cases, plugins on WordPress sites can sometimes lead to a 504 Gateway Timeout error. This issue arises due to plugin-related server workload increases or compatibility issues.

Here’s how to check the website’s plugin for a 504 timeout error recovery:

  1. Access your WordPress admin dashboard and go to Plugins → Installed Plugins.
  2. Deactivate all your installed plugins. If your site becomes accessible afterward, a plugin is likely causing the issue.
Deactivating all installed plugins on the WordPress dashboard
  1. Reactivate each plugin one by one, checking your site after each. If the error reappears, the most recently activated plugin is likely the culprit.
  2. Update the problematic plugin, seek an alternative, or reach out to the plugin’s support team for help.

If you can’t access your WordPress dashboard, use your web host account’s File Manager or an FTP client. Then, navigate to the wp-content directory and rename the plugins folder. This will disable all plugins, allowing you to test if the WordPress website works without them.

Renaming the plugins folder on a File Manager application

After confirming a plugin issue, restore the original folder name to plugins and deactivate each plugin individually to pinpoint the problematic one.

If disabling WordPress plugins doesn’t resolve this issue, the problem might be with your WordPress theme. Switch to a default theme via your dashboard to see if this addresses the problem.

8. Disable your CDN

A content delivery network (CDN) boosts website performance by speeding up content delivery and offering DDoS mitigation. However, it sometimes can be the cause of a 504 Gateway Timeout error as well.

Temporarily disabling your site’s CDN can help diagnose 504 issues. Hostinger customers that have Business plans or above can deactivate the built-in CDN as follows:

  1. Navigate to the hPanel dashboard. Then go to Performance → CDN.
  2. Under the CDN status section, click Disable.
Disabling CDN on the CDN status section of hPanel
  1. Check your website to see if the issue is resolved.

If disabling the CDN allows website access, keep the CDN disabled temporarily. Contact our support team for assistance in resolving this CDN-related problem.

If you’re using a CDN service other than Hostinger’s, first check their system status for any reported issues. You can deactivate most CDN services by logging into your provider’s interface and finding an option to Pause or Deactivate the CDN.

Remember that disabling CDN services may involve DNS changes, which require time to propagate fully. After the DNS propagation finishes, revisit your website to check if the 504 error persists.

9. Check your server resources

If you encounter a 504 error, check your server resources, as server overload is a common cause. Hosting providers allocate specific resources for optimal website performance, but sometimes errors occur.

Hostinger users can check their allocated resources by navigating to Hosting Plan → Resources Usage on hPanel. Pay attention to CPU Usage and RAM Usage. High values suggest an overloaded server struggling with heavy traffic.

When noticing that resource usage is high, reduce your site’s traffic load or optimize performance. If your WordPress site has already reached its hosting limits, consider upgrading your plan.

Server timeouts may happen if PHP scripts exceed the server’s set execution time. Extending the maximum execution time limit can prevent such timeouts.

If you use Hostinger, you can increase the WordPress maximum execution time value via hPanel:

  1. From the hPanel dashboard, navigate to Advanced → PHP Configuration.
  2. In the PHP Options tab, locate the maxExecutionTime field, the default setting being 30 seconds.
  3. Increase this value to 60 seconds and hit Save. If issues persist, consider increasing it further to 120 or 180 seconds.
Increasing the maxExecutionTime value in the PHP options tab of hPanel

Important! Avoid setting the max-execution-time value to 0, as this allows PHP scripts to run indefinitely, potentially consuming excessive server resources as a result.

You can also increase the maximum execution time by editing your WordPress site’s .htaccess file. Here’s an example snippet to add to the file:

php_value max_execution_time 60

Adjust the number as needed for your WordPress site.

10. Configure your Apache and NGINX settings

For websites on VPS hosting, adjusting Apache and NGINX settings can manage server timeouts and resolve 504 errors. Here’s how to change settings on both Apache and NGINX servers:

Apache

  1. Locate the Apache configuration file, typically named httpd.conf or apache2.conf, and open it with a text editor.
  2. Modify the Timeout directive to a higher value. For instance, change from the default 60 seconds to 600 seconds with:
Timeout 600
  1. Save the changes and exit the editor.
  2. Proceed by editing the php.ini file.
  3. Increase the max_execution_time directive. The default value is typically 30 seconds. Increase it to 300 seconds with:
max_execution_time = 300
  1. Save your changes, then restart Apache:
sudo service apache2 restart.

NGINX

  1. Find the NGINX configuration file, usually located in /etc/nginx/nginx.conf.
  2. For sites running on NGINX + FastCGI Process Manager (PHP-FPM) or using NGINX as a reverse proxy for Apache, adjust the following values:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
fastcgi_read_timeout 300;
  1. Reload the NGINX server to implement the changes.
sudo service nginx reload
  1. Edit the PHP-FPM pool config file found in /etc/php/[version]/fpm/pool.d/www.conf. Replace [version] with your PHP version.
  2. Set request_terminate_timeout = 300 to increase the limit.
  3. In the php.ini file, set max_execution_time = 300.
  4. Reload PHP-FPM and NGINX to apply the changes.
sudo service php[version]-fpm reload && sudo service nginx reload

11. Contact your hosting provider’s customer support

When you’ve tried all other methods and still face a 504 Gateway Timeout error, it is best to reach out to your hosting provider’s customer support for help.

When contacting support, be as detailed as possible about your issue. Include your website URL, the gateway message you’ve encountered, and a summary of the steps you’ve already taken to try to resolve the issue.

Hostinger users can quickly get help from Kodee, our AI Assistant, by clicking the Ask Kodee button in the bottom-right corner of hPanel. Just type your concern into the chat and let us know which website is experiencing the error, and Kodee will instantly help troubleshoot the issue.

If you need further assistance, Hostinger’s Customer Success team is also available 24/7.

What causes 504 Gateway Timeout error?

A 504 Gateway Timeout error happens when a server takes too long to respond, stopping a web page from loading. Some common triggers include:

  • Connectivity issues. General network equipment problems can lead to temporary connectivity issues, affecting communication across multiple web browsers, devices, and websites.
  • Proxy server issues. Problems with proxy servers can disrupt the communication pathway between your server and the upstream server, leading to such potential timeouts.
  • Firewall issues. Firewalls, especially those with DDoS protection and mitigation systems, may mistakenly block requests. This is often due to faulty configuration or restrictions on certain ISPs or content delivery networks like Cloudflare.
  • DNS issues and unresolvable domains. Issues can arise when DNS servers are unable to resolve the domain name’s correct IP address. Causes may include incorrect DNS configuration, outdated DNS caches, or recent changes in IP addresses.
  • Server connectivity issues. Broader connectivity problems between servers can result in a 504 error, often stemming from network or hardware issues.
  • Upstream server problems. If the upstream server is down or unresponsive, it can directly lead to a 504 error.
  • Web server overload. When a web server is overwhelmed with requests or running low on resources, it can slow down or halt responses entirely, leading to timeouts.
  • Limited PHP workers. Websites with an insufficient number of PHP workers can experience delays in processing requests, causing timeouts, especially when handling multiple simultaneous requests.

To prevent 504 Gateway Timeout errors, ensure you regularly monitor server loads and optimize website resources. Proactive server maintenance and efficient content delivery can reduce the chances of encountering this web server timeout error.

504 Gateway Timeout error variations

The 504 Gateway Timeout error can manifest in several different forms depending on a web browser, server configuration, and operating system.

An example of the 504 Bad Gateway Timeout error

These are some common 504 error variations you might encounter:

  • 504 Gateway Timeout. The standard 504 error message.
  • HTTP 504 Error. Highlights it as an HTTP status code.
  • Server Error – 504. Emphasizes that the issue originates from the server.
  • Gateway Timeout Error. Directly indicates a timeout at the server gateway.
  • 504 Gateway Timeout NGINX / NGINX 504 Gateway Timeout. Specific to NGINX servers, indicating a gateway timeout.
  • Error 504 / HTTP Error 504 / HTTP Error 504 — Gateway Timeout. Different expressions of the error, focusing on the HTTP request failure.
  • This page isn’t working — Domain took too long to respond / 504 Gateway Time-out — The server didn’t respond in time. A more user-friendly phrasing explaining that there’s been a delay in response.
  • The page request was canceled because it took too long to complete. Indicates a timeout in processing the page request.
  • Site visitors: There was an issue serving your request, please try again in a few minutes. Suggests website visitors should access the page later due to a delay in serving the request.
  • Site owners: There was a gateway timeout. You should visit your error log for more information. The website owner is advised to check the error log for further details.

How 504 Gateway Timeout error affects SEO

504 Gateway Timeout errors can negatively impact a site’s search engine optimization (SEO) if they occur frequently or persist for an extended period. It’s because search engines like Google use HTTP status codes to assess the health and accessibility of a website.

If a website regularly returns a 504 status, search engines might perceive it as unreliable, potentially leading to a lower ranking in search engine results. To minimize SEO damage during downtimes caused by 504 errors, consider implementing these tips:

  • Prompt resolution. Quickly resolving 504 errors is essential to lessen their impact on SEO. Regular monitoring and taking immediate action when issues are detected are crucial.
  • Communicate with users. Use social media or other communication channels to inform your audience about the downtime and the steps being taken to resolve the issue.
  • Temporary downpage. Create a temporary informational page to inform website visitors and search engines that you are aware of the problem and are working on it.
  • Regular website backups. Consistently maintain backups of your website. If a 504 error lasts for a prolonged period, restore a backup file to minimize downtime.
  • SEO monitoring tools. Employ SEO monitoring tools to keep track of issues that may affect your SEO, allowing quicker responses and resolutions.

504 Gateway Timeout vs 502 Bad Gateway

Apart from the 504 Gateway Timeout, other common errors within the 500 range include 502 Bad Gateway and 503 Service Unavailable. Each gateway timeout response represents different server-side issues in handling requests, requiring specific troubleshooting approaches for resolution.

The 504 Gateway Timeout error shares some similarities with the 502 Bad Gateway error, as both indicate issues with server communication. The key difference is that a 504 error happens when there’s a delay in the server’s response, while a 502 error occurs when a server gets an invalid response from another server.

It’s crucial to fix any error messages quickly to keep your site running smoothly and protect your SEO. Check out our guide on the complete list of HTTP status codes to help you stay ahead of problems. Alternatively, you can download the cheat sheet below for quick reference.

Download comprehensive HTTP status codes cheat sheet

All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.

Author
The author

Ariffud Muhammad

Ariffud is a Technical Content Writer with an educational background in Informatics. He has extensive expertise in Linux and VPS, authoring over 200 articles on server management and web development. Follow him on LinkedIn.