12 Effective Ways to Fix the 504 Gateway Timeout Error

Try this guide with our instant dedicated server for as low as 40 Euros

504 Gateway Timeout

Have you ever come across the 504 Gateway Timeout error page while browsing websites? 

From a user perspective, this error affects the user experience. In the context of eCommerce stores, this error can become an acute challenge in terms of brand reputation and revenues. 

As such, fixing this issue is often the priority of website owners and developers. So, in this tutorial, we will try to understand what is 504 Gateway Timeout Error, what are the typical reasons for this issue, and how 504 Gateway Timeout error affects users and the functionality of websites, and possible fixes.

We will start with a detailed introduction to the 504 Gateway Timeout issue.

Table Of Contents

  1. What is Meant by the 504 Gateway Timeout Error?
  2. Variations of the 504 Bad Gateway Timeout Error
    1. 504 Gateway Timeout
    2. 504 Gateway Timeout Cloudflare
    3. 504 Gateway Timeout Reverse Proxy
    4. 504 Gateway Timeout Load Balancer
    5. 504 Gateway Time-out
    6. 504 Error
    7. NGINX 504 Gateway Timeout
    8. 504 Gateway Timeout Apache
  3. Factors Behind The 504 Gateway Timeout Error
    1. Slow Upstream Server Response
    2. Maintenance or Downtime
    3. Firewall issues or Security Software
    4. Unresolvable Domains and DNS Issues
    5. Limited PHP Workers
    6. Network Issues
    7. Large File Transfers
    8. Server Overload
    9. Faulty Proxy Configuration
    10. Server Misconfiguration
  4. 12 Ways to Resolve 504 Gateway Timeout Error
    1. Fix #1: Refresh the Page
    2. Fix #2: Check Proxy Settings
    3. Fix #3: Disable The Firewall
    4. Fix #4: Flush the DNS Cache
    5. Fix #5: Restart the Router
    6. Fix #6: Check DNS Propagation
    7. Fix #7: Access Website’s Error Logs
    8. Fix #8: Modify the PHP Execution Time
    9. Fix #9: Check the Plugins on Your WordPress Websites
    10. Fix #10: Monitor Server Resource Usage
    11. Fix #11: Optimize Server Configuration
    12. Fix #12: Disable the Content Delivery Network
  5. Conclusion
  6. FAQs

What is Meant by the 504 Gateway Timeout Error?

504 Gateway Timeout error is an HTTP status code that the client receives when a server working as a proxy or gateway does not get a response from an upstream server within the allotted period.

This error usually arises when a user’s requests to visit a website or online application are forwarded via one or more intermediary servers (proxies or gateways). If one of these intermediate servers does not generate a timely response for the intended server, the requesting server returns a 504 Gateway Timeout error to the client.

Variations of the 504 Bad Gateway Timeout Error

The 504 Bad Gateway Timeout error can manifest in several variations, all indicating the same underlying issue of the server being unable to receive a timely response from an upstream server. 

Some common variations include:

504 Gateway Timeout

This is the standard form of the error, indicating that the gateway server did not receive a response from the upstream server within the stipulated time frame.

504 Gateway Timeout Cloudflare

In cases where Cloudflare CDN or proxy service is used as an intermediary, the error message may specify Cloudflare to indicate that the timeout occurred while communicating with Cloudflare’s servers.

504 Gateway Timeout Reverse Proxy

In environments with reverse proxy servers, such as NGINX or Apache configured as reverse proxies, the error may indicate a timeout while forwarding requests to backend servers.

504 Gateway Timeout Load Balancer

When a load balancer distributes incoming traffic across multiple servers, an error may occur due to a timeout while the load balancer server waits for a long time for a response from one of the backend servers.

504 Gateway Time-out

This is another common variation of the standard error message, using slightly different wording but conveying the same meaning.

504 Error

Sometimes, the error message may simply display 504 Error without explicitly mentioning the gateway timeout. However, the underlying issue remains the same.

NGINX 504 Gateway Timeout

If the NGINX web server is the gateway server, the error message may include NGINX to indicate the actual component that failed to perform.

504 Gateway Timeout Apache

If the Apache web server is being used, the error message may include Apache to specify the server software involved.

Factors Behind The 504 Gateway Timeout Error

The 504 Gateway Timeout error can be caused by various factors, including:

Slow Upstream Server Response

The most common cause of 504 status code is the situation where the upstream server takes too long to respond to the request(s) forwarded by the gateway server.

Maintenance or Downtime

Scheduled maintenance or unexpected downtime of the upstream server can cause the main server to display the 504 Gateway Timeout error. 

Firewall issues or Security Software

Overly restrictive firewall settings or security software configurations may block or delay incoming requests, causing timeouts that result in the timeout errors.

Unresolvable Domains and DNS Issues

When DNS servers cannot resolve the domain name’s correct IP address, problems might occur, including unresolvable domains. Possible causes include inaccurate DNS setup or DNS-related problems, out-of-date DNS caches, or recent IP address changes.

Limited PHP Workers

Websites with a deficiency of PHP workers may experience delays in processing requests, leading to timeouts when handling several requests simultaneously.

Network Issues

Connectivity issues, congestion, and routing issues between the gateway and upstream servers can lead to timeout errors.

Large File Transfers

When transferring large files or processing complex requests, the time required to complete the operation may exceed the server’s timeout threshold, resulting in a 504 error.

Server Overload

If the upstream server is overloaded with requests or experiences a high traffic load, it may struggle to respond within the timeout period, resulting in a 504 error.

Faulty Proxy Configuration

Improperly configured proxy server settings or load balancers may fail to properly route requests to the upstream server, resulting in timeouts.

Server Misconfiguration

Incorrect configuration or server settings, such as timeouts set too low, can cause the server to terminate connections prematurely, leading to 504 errors.

12 Ways to Resolve 504 Gateway Timeout Error

Let’s now see the fixes you can apply to resolve the 504 Gateway Timeout error:

Fix #1: Refresh the Page

Usually, the most straightforward and first step in fixing a 504 Gateway Timeout problem is to hard-refresh the page. This can resolve transient connectivity problems, particularly if the error results from a temporary server overload.

Start by clicking your browser’s Refresh button to refresh the page.

Alternatively, use the following keyboard shortcuts. 

  • On Windows, press CTRL+R
  • On macOS, press COMMAND+R

Clear your browser’s site cookies and cache before refreshing to address any additional underlying problems.

If refreshing doesn’t work immediately, wait a few minutes and retry. The server may have resolved the problem in the meantime. If you’re still encountering the error, you need to apply additional 504 Gateway Timeout method debugging and solutions.

Fix #2: Check Proxy Settings

A 504 error may occur when you have to go through a proxy server to access a website. 

Some proxy servers restrict access to specific websites based on the user’s IP address. Alternatively, 504 problems can also result from improper proxy configurations.

Disabling your proxy settings on your computer and reaccessing the website will help you determine whether they are the source of the problem. 

For instance, to disable the proxy on Windows, launch the Settings app by clicking the Start button, and choose the gear symbol.

Click on the button for Network and Internet Connections.

In the left pane, select Proxy. Turn off the Use a proxy server option.

automatic proxy setup
Relaunch the browser and reload the website. 

Fix #3: Disable The Firewall

A firewall protects your computer from internet threats and unauthorized access. However, faulty firewall configuration can unintentionally block valid network requests, which would result in the 504 Gateway Timeout error.

A simple fix is to temporarily disable your firewall. Let’s discuss the specific steps for Windows and macOS.

On Windows, access the Settings menu. Navigate to Privacy and SecurityNetwork and Firewall ProtectionWindows Security.

Network and Firewall Protection

Select the currently-used network (private, public, or domain network) and disable Microsoft Defender Firewall.

On macOS, go to System Preferences. Click Security and Privacy.

Select the Firewall tab. 

Click the lock icon at the bottom-left corner and enter your administrator password.

Uncheck the box next to Enable Firewall to turn it off.

turning off firewall

Fix #4: Flush the DNS Cache

Flushing the DNS (Domain name system) cache can help fix 504 Gateway Timeout and other network connection problems. 

This procedure removes inaccurate or outdated cache files that could prevent your device from connecting to the Internet.

Try cleaning up your operating system’s DNS cache files to resolve client-side DNS problems. Let’s look at the specifics of the process on Windows and macOS.

On Windows, enter cmd in the Start menu and select Command PromptRun as Administrator.

Enter ipconfig /flushdns, and press Enter.

ipconfig-flushdns
You can see confirmation once the system has successfully flushed the DNS resolver cache.

On macOS, go to ApplicationsUtilities. Open Terminal. In the terminal, type the following command:

$ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.

Press Enter

sudo dscacheutil -flushcache
Enter your Administrator password when prompted.

In addition to the OS, the browser also maintains a DNS cache. You also need to clear this cache to complete the fix.

The process of flushing the DNS cache is similar in all web browsers. We will demonstrate the idea for Google Chrome. However, you can apply this process to other browsers. 

Open Chrome and type chrome://net-internals/#dns in the Address Bar.

dns lookup

Click Clear Host Cache to clear Chrome’s DNS cache.

Launch a new tab and reassess the website.

Fix #5: Restart the Router

If the website is down only for you and none of the other fixes resolve the problem, incorrect settings or hardware problems could be the source of the 504 error. 

If that is the case, restart your network device and refresh the page.

Fix #6: Check DNS Propagation

Suppose your website is recently relocated to a new IP address or server. In such cases, you may have to wait up to 48 hours for the DNS propagation process to finish, as Internet Service Providers need to update their records.

Use whatsmydns.net or other similar programs to confirm that the propagation is completed.

For quicker and more dependable DNS resolution for chronic DNS problems, use a public DNS service like Cloudflare 1.1.1.1, Google Public DNS, or Quad9.

Fix #7: Access Website’s Error Logs

When investigating 504 Bad Gateway Timeout errors, we strongly recommend checking the website error logs. These logs contain details of errors (including the 504 events) that you can use as the starting point for investigation and mitigation. 

There are two ways you can access the website error logs.

Use the Hosting Control Panel (e.g., cPanel, Plesk)

Log in to your hosting control panel.

Locate the section for website logs. In cPanel, this is often under Metrics > Errors. In Plesk, you might find it under Websites and Domains > Your Domain > Logs.

Look for error log files or access logs containing information about the 504 errors.

Use SSH for Direct Server Access

Connect to your server using.

Navigate to the directory where logs are stored, often /var/log/ for Linux servers. The exact location can vary depending on your configuration and web server software.

Common log folders or log locations for web server logs include:

In Apache: /var/log/apache2/error.log or /var/log/httpd/error_log

In NGINX: /var/log/nginx/error.log

Access the error log, analyze, and take the right mitigative actions. 

Fix #8: Modify the PHP Execution Time

If the available volume of resources does not cause the 504 problem, try extending the maximum execution time limit of PHP scripts. A server timeout error may occur if a PHP script takes longer to run than the allotted time.

Note that this solution also helps prevent the errors connected to scripts being marked as error sources.

To apply this fix, log into your web hosting account. We will use cPanel for the demonstration. 

Go to SoftwareSelect PHP Version. Select the current PHP version and then go to Options tab. Find the max_execution_time field and change the value accordingly.

Note that by default, the script execution time has a default value of thirty seconds. 

Save the changes after increasing max_execution_time to 60. 

If the issue still exists, increase the value to 120–180 seconds. 

Alternatively, if you have a WordPress website, you can add the Google Pagespeed Insights plugin or alter the .htaccess file.

If you use WordPress and your hosting company does not allow PHP error logging by default, you can activate the debug mode on your website by going through these steps:

Locate the wp-config.php file using the File Manager application. Add the following lines to the file:

define( 'WP_DEBUG', true );

define( 'WP_DEBUG_LOG', true );

define( 'WP_DEBUG_DISPLAY', false );

Save the changes before leaving.

(Note: Check if the WP_DEBUG mode line already exists in the wp-config configuration file; make it true or false according to your needs)

Here:

WP_DEBUG: Indicates WordPress debug mode is enabled.
WP_DEBUG_LOG: Saves all PHP errors in the wp-content/debug.log file.
WP_DEBUG_DISPLAY controls whether or not debug messages appear on HTML pages. When set to false, errors are still logged in the file but hidden on the website.

Fix #9: Check the Plugins on Your WordPress Websites

Active plugins on WordPress websites may occasionally cause a 504 Gateway Timeout issue. This can be due to compatibility problems or increased server workload caused by substandard or malfunctioning plugins.

You can check if there’s a 504 timeout error due to a website plugin by navigating to PluginsInstalled Plugins in your WordPress admin dashboard.

Deactivate every installed plugin. 

If you can access your site now, the problem is probably with one of your plugins.

Now, reactivate each plugin and check your website. The most recent plugin that caused the issue is probably the cause of the error.

You can now update the troublesome plugin, look for a substitute, or ask the support staff for assistance.

Alternatively, if you can’t access your WordPress dashboard, use an FTP program or the File Manager in your web server account. 

Locate the plugins folder in the wp-content directory and rename it. 

Disabling all plugins(including third-party plugins) will now allow you to test for 504 Gateway Timeout errors.

Once a plugin issue has been verified, rename the folder to its original name and deactivate each plugin one at a time to identify which one causes the problem.

If turning off faulty plugins doesn’t fix the issue, your WordPress theme may be the cause. Try changing to WordPress’s default theme to see if the issue is solved.

Fix #10: Monitor Server Resource Usage

Monitoring server resources is a highly recommended best practice to maintain server health by avoiding overload or inadequate resources issues. 

Here are the typical server performance parameters to monitor regularly. 

CPU Usage

High CPU usage can lead to slow request processing, leading to 504 errors. Use tools like top, htop, or Task Manager (on Windows) to monitor server load.

CPU Usage

Memory Usage

Insufficient memory (RAM) can cause swapping, significantly slowing down the server response. We recommend monitoring memory usage using the above-mentioned tools.

Disk I/O

High disk activity can also lead to slow response times. Tools like iotop (Linux) or Resource Monitor (Windows) can help identify disk I/O bottlenecks.

Network Bandwidth

Ensure that the server is not hitting its bandwidth limits. Monitoring tools can provide insights into bandwidth usage to identify issues in data transfer.

Fix #11: Optimize Server Configuration

Optimizing server configuration is also an overlooked solution. Here, we recommend the following optimization strategies for the server and the database.

Web Server Settings

Optimize your web server settings (Apache, NGINX, IIS, etc.) to handle more concurrent requests efficiently. This might involve adjusting worker processes, threads, or connection limits.

Database Optimization

Ensure that the database server is properly optimized for query execution. This could include optimizing queries, indexing, or adjusting database cache settings.

Fix #12: Disable the Content Delivery Network

A Content Delivery Network (CDN) enhances website availability by accelerating content delivery and providing DDoS mitigation. In rare instances, it may cause a 504 Gateway Timeout error.

Disabling the CDN, particularly if the CDN is malfunctioning or misconfigured, is essential to investigate and fix a 504 Gateway Timeout error. The precise procedure may differ depending on the CDN provider.

We will use Cloudflare to demonstrate the process.

Navigate to the Overview tab of your site’s Cloudflare account.

advanced actions

Select the Pause Cloudflare on Site option at the lower-right corner of the webpage. 

By bypassing Cloudflare’s network, you can access your website directly through the IP address of your origin server.

Conclusion

Encountering a 504 Gateway Timeout error can be a frustrating experience for users, leading to disruptions in accessing websites and services. However, with regular monitoring and the application of detailed troubleshooting guides, effective solutions can be implemented to mitigate this issue. Remember to stay proactive in monitoring website performance and implementing preventive measures to minimize such errors in the future, ensuring a seamless and uninterrupted browsing experience for all users.

At RedSwitches, we take pleasure in assisting our valued customers with their unique server needs. We are your global dedicated hosting partner, offering bare metal hosting solutions tailored to enhance your Ruby development experience. 

FAQs

Q. What is a 504 Gateway Timeout error?

A 504 Gateway Timeout error occurs when a server fails to receive a timely response from another server while attempting to load a webpage or complete a request. This typically results from network connectivity issues or server overload.

Q. What causes a Timeout NGINX error?

A Timeout NGINX error may occur when the NGINX server does not receive a response from an upstream server within the default timeout period. This can happen due to network connectivity issues, overloaded servers, or incorrect server settings.

Q. How can I troubleshoot network connectivity issues?

To troubleshoot network connectivity issues, check your network settings, ensure you have an active network connection, and verify that no firewall or routing issues are blocking communication between your device and the server.

Q. What should I do if I encounter a DNS-related problem?

If you suspect a DNS-related issue, try clearing your DNS cache to remove any corrupted entries. Additionally, ensure that your DNS configuration is correct and that unresolved IP addresses are properly resolved.

Q. Why might a server become overloaded?

Servers can become overloaded due to high incoming requests, insufficient server resources, or inefficient server configuration. This can delay processing requests and result in a 504 Gateway Timeout error.

Q. How can I prevent server overload?

To prevent server overload, optimize your server configuration, allocate sufficient resources to handle incoming requests, and implement load balancing and caching strategies to distribute the workload effectively.

Q. Are browser requests a common cause of 504 errors?

Yes, browser requests can contribute to 504 errors, especially if the server cannot process many simultaneous requests or if there are browser issues with client-server communication.

Q. What should I do if I encounter a 504 error in the plugins directory?

If you encounter a 504 error while accessing a website’s plugin directory, it may indicate a problem with the server’s ability to process requests related to plugin functionality. Try disabling or updating plugins to resolve the issue, and ensure that the server configuration is optimized to handle plugin-related requests efficiently.

Try this guide with our instant dedicated server for as low as 40 Euros