Open In App

How To Fix the 504 Gateway Timeout Error on Your Site

Last Updated : 13 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

One of the most unpleasant things that may happen to you when trying to visit a website or service is receiving a 504 Gateway Timeout error. This is the result of an upstream server responding slowly to a gateway or proxy server. It’s similar to phoning someone who is engaged or doesn’t answer the phone.

How-to-Fix-the-504-Gateway-Timeout-Error-on-Your-Site

This thorough article includes a detailed analysis of typical 504 Gateway Timeout error reasons as well as workable solutions for quickly resolving the issue. Smooth online experiences will be ensured whether you are using your own website or someone else’s, provided you can determine the root cause of the problem and resolve it.

What is 504 Gateway Timeout Error?

Your request generally passes through numerous servers before reaching the server hosting the site when you visit any particular website. Any problems with these intermediary servers or if they take too long to respond may lead to a 504 Gateway Timeout error. It’s just like hitting an obstacle or stumbling across another route on your journey toward accessing some specific webpage.

Variations of the 504 Gateway Timeout Error

Before we move into the solutions, let’s first understand the different ways this error can be shown:

  1. 504 Gateway Timeout: The standard error message.
  2. 504 Gateway Timeout NGINX: Specific to NGINX web servers.
  3. Gateway Timeout Error: A more generic term.
  4. HTTP Error 504: The official HTTP status code.
  5. HTTP Error 504 — Gateway Timeout: A verbose version.

Common Causes of the 504 Gateway Timeout Error

There are various factors that can contribute to a 504 Gateway Timeout error, which include:

  • Server Overload: Users might make requests that cannot be handled within a reasonable timeframe when the host is flooded with millions of users.
  • Network Issues: There might be difficulties during communication if the link between the gateway server and an upstream server fails.
  • Timeout Settings: The gateway server may simply stop waiting after a certain period if its timeout settings are not long enough.
  • DNS Issues: The gateway server can forward requests to the wrong server if its DNS settings have been incorrectly done.
  • Firewall or Security Settings: In case firewall or security settings are too severe, some requests might get blocked or delayed leading to timeout error.

How to Fix the 504 Gateway Timeout Error

1. Refresh the Page

You can resolve the 504 issue by reloading the page. Your browser sends a fresh request for an updated version of the page to the server whenever you refresh a webpage.

Use Ctrl+R (Windows/Linux) or Cmd+R (Mac) to refresh a webpage. As an alternative, you can click the browser’s reload button, which is situated in the address bar, or right-click the page and choose “Refresh.”

2. Check Other Websites

When a particular website gives you a 504 error, it is important that you check others to see if they open well. This step will help establish whether the problem is only on the site that you want to access or if it is more of internet issue.

3. Clear Browser Cache

Among other loading issues with a web page, 504 Gateway Timeout failures can be caused by a number of issues, including browser cache and cookies. By optimising your browser’s performance and removing files from it, you can fix these problems.

Google Chrome:

  1. In the upper right corner of the window, click the three dots menu symbol.
  2. Decide to “Clear browsing data” under “More tools”.
  3. Choose a time frame in the popup window for the information you wish to delete (you can pick “All time” to remove cookies and cached files).
  4. The check boxes for “Cached images and files” and “Cookies and other site data” should be checked.
  5. Press the “Clear data” button.

Clear Browsing Cache 504 Gateway Timeout Error

Try reloading the page that is displaying the 504 error after deleting the cache and cookies from your browser. This may fix the problem by forcing your browser to download an updated version of the website straight from its server.

Check Out: Difference between Cache and Cookies

4. Restart Your Computer and Network Devices

Some networking issues may be resolved by restarting your computer when faced with a 504 error. Restarting a computer can result in refreshed network connections and settings that could be useful in solving 504 Gateway Timeout error issue. Moreover, Rebooting other related network devices such as routers modems will renew network connections and clear transitive issues. Always remember the proper order of power-up starting from the internet service provider (ISP) device towards your computer. This can remove any networks that cause the 504 gateway timeout.

5. Flush DNS

Flushing DNS cache can resolve DNS-related problems that are leading to a 504 error message. In order to flush your DNS cache, open either command prompt (Windows) or terminal (Mac/Linux) on your operating system:

  • Windows: ipconfig /flushdns

Flush DNS

Flush DNS- 2

  • Mac: sudo killall -HUP mDNSResponder
  • Linux: Depending on your distribution, use systemctl restart systemd-resolved.service for systemd-based systems (e.g., Ubuntu 16.04 and later) or sudo systemctl restart nscd for nscd-based systems.

6. Check Plugins and Themes

A faulty plugin or theme could contribute towards a 502 Bad Gateway error message. Sometimes both themes or plugins have flaws in their codes leading to disturbances in how sites normally work. For example, caching and security plug-ins may complicate server-to-server communications leading to this error. The problem can be addressed by disabling all your plugins and then turning on one at a time so as to pinpoint the cause of the problem plug-in. Here is how:

  1. Disable Plugins:
    • On your site’s dashboard, go to the Plugins section
    • From the options select ‘Deactivate’ for all plugins.
    • Refresh your website after each deactivation to see if the error is resolved.
    • Once this occurs again, you will know which plugin is causing it.
  2. Disable Themes:
    • If disabling these widgets doesn’t help, you should also try turning off some themes.
    • In your website’s installation using the hosting panel or FTP program navigate to the themes directory.
    • Rename that directory that is named “themes-disable” for instance in order to fix errors with 502 status code showing up..
    • See whether your website starts working without any 502 errors.
    • If it does, rename the directory back to ‘themes’ and try activating your themes one by one until you find out what theme causes trouble..

By following this process of elimination you will get a clearer idea of how to fix any conflicts that are causing a 502 Bad Gateway.

7. Disable Your Firewall

Firewalls can sometimes block legitimate requests causing a 504 Gateway Timeout Error. To confirm this temporarily disable your firewall. In case the firewall has been disabled and the error has gone away, then you need to enable these connections by adjusting your firewall settings.

8. Check Error Log

A 504 Gateway Timeout error may occasionally appear after you have updated anything specific or made changes; this indicates that there is a problem with your server. If this occurs, examine the website’s log file for issues.

Most hosting services provide access to enable the website error log through an admin dashboard. For WordPress sites, you can enable error logging by adding the following lines to your wp-config.php file:

define( 'WP_DEBUG', true );  
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

All errors will be logged in the wp-contents/debug.log file, helping you identify the cause of the 504 Gateway Timeout error.

9. Disable the CDN

Web material is sent faster through a global network of servers known as content delivery networks (CDNs). CDNs are meant to make websites more efficient but sometimes they can cause delays leading to 504 Gateway Timeout errors.

Turning off CDN temporarily helps in finding if this relates to CDN or not. This is how you disable CDN:

  • Access CDN Settings: Log into your own personal dashboard or control panel with your CDN provider.
  • Disable CDN: Search for a setting that allows you deactivate or suspend the functionality of the content delivery network. This typically occurs under settings/configuration tab on your CDN provider’s dashboard.
  • Clear Cache (Optional): In case your CDN caches some content, remember to remove it before turning it off so that people accessing your site receive fresh materials straight from its source server.
  • Verify Website Access: Go directly on your site after disabling this service (without using any contents). See if this 504 issue has been fixed.

If turning off the Content Delivery Network solves the 504 problem, then perhaps it may be due to either configuration or performance issues with regards to CDNs.

10. Check for Spam, Bots, or DDoS Attacks

The server can also be overwhelmed by spam, bots, or Distributed Denial of Service (DDoS) attacks leading to a 504 Gateway Timeout error. So here are ways to check and tackle these problems:

  • Traffic Monitoring: Use tools for monitoring traffic in order to detect any significant traffic spikes indicative of DDoS attack.
  • Firewall Rules: Implement firewall rules that will block suspicious IP addresses or traffic patterns. This can help reduce the impact of DDoS attacks and minimize server loads.
  • Security Plugins Installation: Use security plugins or services which can detect and prevent spam or bot traffic. These are resources that can guard against malicious activities on your website.
  • CAPTCHA Activation: You may activate CAPTCHAs on forms and login pages to prevent automated bots from accessing your site.
  • Security Measures Update: Stay informed about current security measures like software updates and patches for your website in order to detect new vulnerabilities.

This way you will protect yourself from such attackers as spam, bots, and DDoS attacks hence minimizing chances of seeing 504 Gateway Timeout errors.

11. Configure Apache and NGINX Settings

While the specific configuration steps may vary depending on your server setup and software versions, here’s a general guide on adjusting server timeouts for Apache and NGINX to potentially address 504 errors:

Apache:

  1. Locate the configuration file: This file is typically named httpd.conf or apache2.conf and can be found in the Apache configuration directory. The exact location may differ based on your operating system and installation choices. Consult your server documentation for specific guidance.
  2. Increase the timeout value: Edit the configuration file and find the Timeout directive. Increase the value to a higher duration, such as 600 seconds (10 minutes). This directive controls the maximum time the server waits for a response from another server before timing out.
  3. Save and restart: Save the changes to the configuration file and restart the Apache service using the appropriate command for your operating system (e.g., sudo service apache2 restart on Ubuntu/Debian).

NGINX:

  1. Locate the configuration file: The NGINX configuration file is typically named nginx.conf and can be found in the /etc/nginx directory.
  2. Adjust timeout values: If you’re using NGINX with PHP-FPM (FastCGI Process Manager) or as a reverse proxy for Apache, locate the following directives and adjust their values to a higher duration (e.g., 600 seconds):
    • proxy_connect_timeout
    • proxy_send_timeout
    • proxy_read_timeout
    • send_timeout
    • fastcgi_read_timeout (if applicable)
  3. Reload NGINX: Save the changes to the configuration file and reload the NGINX service using the appropriate command (e.g., sudo service nginx reload).
  4. Additional configuration (if applicable):
    • For PHP-FPM setups, locate the pool configuration file (e.g., /etc/php/[version]/fpm/pool.d/www.conf) and set the request_terminate_timeout value to a higher duration (e.g., 300 seconds).
    • Edit the php.ini file and adjust the max_execution_time directive to a higher value (e.g., 300 seconds) if necessary.
  5. Restart services (if applicable): After making changes to PHP-FPM or php.ini, restart the relevant services using the appropriate commands (e.g., sudo service php[version]-fpm reload).

Important Note: Note that this is not a long-term solution and should only be used as a temporary troubleshooting measure. It is generally very critical to look into the primary source of the 504 errors in order to address the underlying problem in an efficient manner.

Check Out: Difference between Apache and NGINX

11. Contact Hosting Provider

Consider contacting your hosting company if you are still receiving 504 Gateway Timeouts after trying every other troubleshooting solution. This is due to their ability to distinguish between various server-related issues using more sophisticated data and technologies.

Conclusion

To sum up, the 504 Gateway Timeout error can be infuriating but temporary server or network problems usually cause it. To normally correct such errors, refresh the page, clear the cache on your browser and check for network problems. However if those things don’t work out I would recommend contacting your hosting company who will help you with this situation. Therefore, following these steps can make you fix 504 easily and get back online again.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads