X
X

Knowledge Base

HomepageKnowledge BaseServer/VPS/VDSHow to fix 504 Gateway Timeout Erro...

How to fix 504 Gateway Timeout Error - Troubleshooting Guide and Solutions

How to fix 504 Gateway Timeout Error - Troubleshooting Guide and Solutions

How to fix 504 Gateway Timeout Error - Troubleshooting Guide and Solutions

Introduction

Dealing with a 504 Gateway Timeout error can be frustrating when trying to visit a website or service. This error occurs when an upstream server responds slowly to a gateway or proxy server, much like trying to call someone who is busy or unavailable to answer the phone.

Delve into this detailed article for a comprehensive analysis of the typical reasons behind the 504 Gateway Timeout error, accompanied by actionable steps to resolve the problem efficiently. By diagnosing and fixing the issue at its core, you can maintain seamless online performance whether you are managing your website or accessing others'.

504 Gateway Timeout – What is it about?

Visiting a website involves your request passing through several servers before reaching the server that hosts the site. If there are any problems with these intermediary servers or if they take too long to respond, you may encounter a 504 Gateway Timeout error. This is akin to facing an obstacle or discovering an alternative route while trying to access a specific webpage.

Variations of 504 Error

Before we proceed with the solutions, let us first familiarize ourselves with the different ways in which this error may manifest:

- 504 Gateway Timeout: The standard error message.
- 504 Gateway Timeout NGINX: Specific to NGINX web servers.
- Gateway Timeout Error: A more generic term.
- HTTP Error 504: The official HTTP status code.
- HTTP Error 504 — Gateway Timeout: A more elaborate version.

Causes of 504 Error

Multiple factors can play a role in causing a 504 Gateway Timeout error, such as:

Overloaded Server: When the server is flooded with millions of users, it may struggle to handle requests promptly, leading to overload. The second server does not always have to be external, for example, a CDN or API gateway. It can also serve as a server-like entity within the main web server, like a reverse proxy server or a database server.

Problems with the Network: Network issues may arise if there are difficulties in communication due to a failure in the link between the gateway server and an upstream server.

Non-optimal Timeout Settings: The gateway server may simply stop waiting after a pre-defined period if its timeout settings are not optimal. Likely, the issue does not lie with the client's device or internet connection. This also applies to your device and connection.

Incorrect DNS Adjustments: The gateway server can push requests to the incorrect server if its DNS records have been incorrectly set or modified.

Strict Firewall Rules: In case firewall or security rules are set too stringent, some requests might get denied or delayed leading to a 504 error.

So, how to fix 504 Gateway Timeout error?

Now, we will see how the issue could be fixed. It also shows how it could be related to other things:

1. Try Reloading the Webpage: To resolve the 504 error, simply refresh the page. By reloading the page, your browser will send a new request to the server for an updated version of the webpage. You can do this by using Ctrl+R (Windows/Linux) or Cmd+R (Mac), clicking the browser's reload button in the address bar, or right-clicking the page and selecting "Refresh."

If you encounter a 504 error on a specific website, it's a good idea to check other websites to ensure they are loading properly. This will help determine if the issue is isolated to the site you are trying to access or if it is a broader internet problem.

In addition to other potential causes of loading issues, 504 Gateway Timeout errors can be triggered by browser cache and cookies. By clearing your browser's cache and optimizing its performance, you can address these problems effectively.

2. Reboot your Devices: When faced with a 504 error, restarting your computer may help resolve networking issues. This can result in refreshed network connections and settings, which could be beneficial in solving the 504 Gateway Timeout error. Additionally, rebooting routers and modems can renew network connections and clear any transitive issues. Always remember to power up devices in the proper order, starting from the ISP device towards your computer, to eliminate any networks causing the 504 gateway timeout.

3. If a Proxy Server is Being Used to Connect to the Internet: Positioned between your device and the Internet, a proxy server is primarily employed to heighten online privacy by obscuring personal details (like device location) from websites and webservers (e.g. via a VPN). If encountering a 504 error, improper proxy server settings could be the cause. Try disabling the proxy server and reloading the webpage to potentially rectify the issue.

4. Investigate for DNS Issues: If you encounter a 504 Gateway Timeout error, it could be due to DNS issues on the server side, the client side, or both. One common cause of server-side DNS problems is the failure of the FQDN to resolve to the correct IP address or the unresponsiveness of the DNS server. This is often observed after migrating a site to a new server or host, so it's important to be patient as the domain's DNS records may take up to 24 hours to fully propagate.

When troubleshooting client-side DNS problems, it may be helpful to flush your local DNS cache. This is comparable to clearing your browser cache, except in this scenario, you are purging the DNS cache from the operating system.

If running Windows, issue this command:

ipconfig/flushdns

On MacOS:

sudo killall -HUP mDNSResponder

On 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.]

You can temporarily modify your client-side DNS servers. By default, your ISP will automatically allocate DNS servers to you. Nonetheless, you have the flexibility to switch to public DNS IPs on a temporary basis.

It is worth exploring Google Public DNS (8.8.8.8/8.8.4.4), Cloudflare 1.1.1.1, Quad9 DNS (9.9.9.9/149.112.112.112), and Cisco OpenDNS (208.67.222.222/208.67.220.220) as they are reliable choices for DNS servers.

5. Turn Off CDN: At times, the problem may also stem from your content delivery network (CDN). If a website's origin server cannot be reached, many CDNs will try to deliver the complete webpage from their cache. One simple way to troubleshoot this is by temporarily disabling your CDN. For instance, if you are employing the free CDN Enabler WordPress plugin to associate your site assets with CDN URLs, you can deactivate the plugin and try reloading your site. The same process applies to any other plugins utilized to connect to your CDN (e.g. WP Rocket, Breeze, W3 Total Cache).

6. Check for Spam, Bots, or DDoS Attacks: Protect your server from spam, bots, or DDoS attacks to prevent a 504 Gateway Timeout error. Monitor traffic, establish firewall rules, and use security plugins to enhance your website's security and minimize the risk of encountering such issues.

Enable CAPTCHAs on forms and login pages to block automated bots from entering your site. Keep up with security measures by regularly updating software and applying patches to your website to identify and address new vulnerabilities. By doing so, you can safeguard against spam, bots, and DDoS attacks, reducing the risk of encountering 504 Gateway Timeout errors.

7. Contact your Hoster: In case you are encountering persistent 504 Gateway Timeouts even after exhausting all troubleshooting options, it is recommended to get in touch with your hosting company. They have the capability to differentiate between various server-related issues using advanced data and technologies.

8. Infrastructure Issues: If your server is struggling to handle the load, it may result in your website becoming unresponsive. To resolve this issue, consider upgrading to a server with improved infrastructure. Web Design Labs’ basic hosting plan is capable of managing a static site with medium traffic.

9. Increase/Modify PHP Resources: PHP workers (in php-fpm) play a vital role in executing your website's code effectively. A high-traffic ecommerce site attracting 50,000 visitors per month requires greater server resources than a basic blog with the same traffic volume. When all PHP workers on the server are in use, a queue will form. If this queue becomes too lengthy, the server may begin disregarding older requests, leading to a 504 gateway error. To prevent such issues, consider reaching out to your hosting provider to increase the number of PHP workers, allowing your site to handle multiple requests concurrently.

10. Verify Firewall Settings: Errors or misconfigurations within your server's firewall could be causing issues. Some rules within the firewall may be blocking the server from establishing connections correctly. To troubleshoot this, examine the error logs on your server.

11. Connectivity/Load Balancer Issues: Connectivity problems between the proxy server and the web server might result in delays when responding to HTTP requests. Furthermore, network connectivity issues with a load balancer could also contribute to performance issues.

12. HTTP Timeouts: HTTP timeouts may occur if the connection between the web server and the client remains open for an extended period. In the case of WordPress sites, this issue commonly arises during WordPress imports. One effective solution is to switch to a faster internet connection.

To address HTTP timeouts, consider utilizing a tool that supports WP-CLI to execute scripts directly on the server, bypassing the need for an HTTP connection. For example, you can utilize the wp import WP-CLI command to directly run the WordPress Importer plugin via the command-line interface.

Note: It is crucial to differentiate between 504 Gateway Timeout errors, 503 Service Unavailable errors, and 502 Bad Gateway errors. While they may appear similar, each error signifies a distinct issue.

Conclusion:

Your website may encounter the 504 Gateway Timeout error due to various factors. This guide has equipped you with troubleshooting techniques to address them effectively. Typically, such errors stem from server-related issues, prompting you to contact your hosting provider for a swift resolution.

It's important to note that the 504 Gateway Timeout error can also result from third-party plugins, themes, services, inefficient database queries, or a combination of these factors. If your server resources are being pushed to the limit (e.g. PHP workers), optimizing your website for better performance is advisable.

If you continue to experience timeouts on your site, it may be necessary to upgrade your hosting plan or increase the number of PHP workers. I suggest exploring this option only after exhausting all other solutions outlined in this guide.

 

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(24 times viewed / 0 people found it helpful)

Top