- Possible Reasons behind 504 gateway timeout Error.
- Easy methods to fix “504 gateway timeout error”.
- Time to fix the “504 gateway timeout error” like a Pro.
For as long as internet has existed, users have seen this error one time or the other.
“504 gateway timeout error”
There are many numbers of errors we face while using the internet. You must have encountered one of the very generic error, that is ‘504 Gateway Timeout’ error while browsing the internet. It appears suddenly from nowhere, ruining your web browsing experience for just a few seconds if you are lucky. Otherwise, it takes time to figure out the actual reason behind the error. Once you get the cause, you will have to fix it.
You don’t need to worry about it, as we know the possible reasons, as well as their solutions. It might take 2-3 attempts to fix it. But one thing is certain that you will be able to kick out this error with the help of this article.
Before we move ahead towards its solution, we need to know what actually ” 504 gateway timeout error” is and the reason behind its occurrence.
What is “504 Gateway Timeout” error?
To understand what is 504 gateway timeout error, you need to know how exactly you get the requested web pages on your desktops, mobiles, laptops and on any possible device. When you request a webpage, based on the IP address of the server( provided by the DNS server) your computer tries establishing a connection to the server on which the webpage is hosted or the web pages are stored. In this process, the request passes through so many intermediate DNS servers as well as proxy servers.
It happens very quickly that we never get to know what is actually happening in the background, most of us are not even bothered about it. In most of the cases, we get the requested results. But, sometimes a server among many servers in the connection cycle fails to give any response(also known as connections-drop ) and the complete cycle comes to a halt showing 504 gateway timeout error.
The code “504” for gateway timeout error is a globally accepted standard code, every browser and every operating system is developed in a way to display this error when the connection request is not going through any server. It means when any server in between sender and receiver, or the receiver itself fails to respond in a certain amount of time, this error should pop up.
Let’s make the scenario more clear with a very technical example. Many servers administrator while setting up a web server implement a proxy server such as Nginx in frontend and Apache in the backend.When the proxy server gets the request from the client via any web browser, the proxy server acts as a gateway and forward the request to the web server at the backend. If the web server fails to respond in a certain amount of time, it will give 504 gateway timeout error in any of the following forms, depending on the browser settings.
- 504 – Gateway Timeout
- 504 Gateway Timeout Error
- Gateway Timeout (504)
- HTTP Error 504 – Gateway Timeout
- Gateway Timeout Error
- A blank white screen
- HTTP 504
- Few websites have their own designed custom error page.
Technically 504 gateway timeout error is actually a HTTP status code. HTTP response status codes indicate whether a specific HTTP request has been successfully completed or not.
Though it is an error, it prevents your computer from getting into an endless loop of re-initiating a connection request again and again with the failing server, that might be down or may be facing some network issues.
Possible reasons behind 504 gateway timeout error.
After understanding what exactly 504 gateway timeout error is, you will certainly be curious to know why it occurs. It’s important to understand how they are generated before we start fixing the issue. So, here we are to discuss the possible reasons behind this error.
1. Server Issues: Sometimes the web server has a very low technical configuration ( Ram, hard disk, processor and many other vital components of less capacity or bad quality). Also, when the technical configuration is good, it is not optimized properly which creates performance issues which finally leads to timeout errors. In such cases, you should upgrade your hosting plan. If you are already on a good plan, ask your hosting provider to check and provide the reason for high resource utilization or to upgrade their server.
2. Network issues: If the network link between the intermediate proxy server and the web server is weak, it will create a considerable lag between HTTP/HTTPS request and response and will produce timeout errors.
3. DNS settings: If the DNS(Domain name server) is not configured properly for the domain, there will be a problem in resolving the domain name to IP address, which our browser needs to query web pages from the web server. which can produce timeout errors.
4. Browser settings: If the browser settings are not correctly configured, it can produce connectivity problems in initiating a connection to the web server.
5. Proxy server issue: If all the connection request is going through the proxy server and the timeout value set on the proxy server is very short, it will frequently produce timeout errors.
6. Firewall misconfiguration: The web server firewall has a set of rules to control inbound as well as outbound traffic, using these rules you can allow or restrict connections to the web server. If the firewall is not configured properly or if a rule is set to restrict the connection to the server, it will produce timeout errors.
504 timeout error and your website ranking.
Your websites are constantly crawled by Google ranking your website, its a part of SEO(search engine optimization). If your site is down for a few minutes due to 504 timeout error, it will get crawled from the cache or if you are lucky your site will be up before the google re-crawl your website. But, if you were not able to get rid of this error for hours then it will surely affect your ranking. Every website holder knows the importance of Google ranking.
Easy methods to fix “504 gateway timeout error”.
Now, we know what is 504 gateway timeout error. We also know the possible reasons behind 504 gateway timeout error. Now, it’s the time for the real action, it’s the time to know how you can fix the 504 gateway timeout error.
Before we dive in deeper towards the fixing techniques, there are a few things which are worth trying and which may fix the issue without doing a lot. And also, not every time the problem is on the server side, many times the issue is on the client side.
To check and confirm whether the issue is at your end or the server’s end we need to follow the very easy steps given below.
- Try refreshing the website or the application.
- Check firewall rules.
- Try restarting the network.
- Cross-check the proxy server settings in the browser or application are correct or not.
- Try loading the website in a different browser.
- Try loading the website in incognito mode.
- Try to force refresh the webpage to clear your website’s cache. Sometimes the issue is due to stored cache in your system.
“You must be wondering what is “force refresh”? It is not that complicated as it sounds. With an intention to speed up web browsing, web browsers are made in a way to download frequently visited web pages locally on your computer which is termed as browser cache. Browser cache holds almost everything you have seen or downloaded while browsing. So when you visit the same page again, it reduces the wait time by loading the page from locally stored cache also helps in reducing bandwidth consumption.”
Depending on your operating system you need to do hit following key combination while being on the browser.
Windows: Ctrl + F5
Mac/Apple: Apple + R or command + R
- If force refreshing doesn’t help, you should try flushing your DNS(domain name system) cache.
For Windows: Press the Windows+R key combination in order to open the Run dialog box. Type cmd and click the OK button. A command prompt will appear, type “ipconfig /flushdns” and press enter button.
**For Linux: ** Open terminal and type “sudo /etc/init.d/nscd restart” and press enter button.
For MacOS: Open terminal and type “sudo killall -HUP mDNSResponder” and press enter button.
*\\Please note that these commands may change with time.***
It’s great if you were able to resolve the 504 gateway timeout error with the easy steps given above, still stuck with the error? Don’t worry, it simply concludes that the error is not at the client side, it is actually at the server side. In such cases we need to check the web server multiple error logs, error log location depends on the operating system of the servers as well as the CMS used. Once you get into the right log, you will get the actual reason behind the timeout errors.
Time to fix the “504 gateway timeout error” like a Pro.
1. Use different DNS Server
By default, the DNS servers are configured as per the ISP’s DNS server. But, a good practice is to replace the ISP’s DNS with public DNS services like Google DNS, Cloudflare privacy-focused DNS, Cisco’s OpenDNS. These DNS servers keep updating their DNS records periodically.
For Example: Changing DNS server settings on Windows 7(By Google)
Go to the Control Panel.
Click Network and Internet > Network and Sharing Center > Change adapter settings.
Select the connection for which you want to configure Google Public DNS. For example:
- To change the settings for an Ethernet connection, right-click Local Area Connection > Properties.
- To change the settings for a wireless connection, right-click Wireless Network Connection > Properties.
- If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
- Select the Networking tab. Under This connection uses the following items, select Internet Protocol Version 4 (TCP/IPv4) or Internet Protocol Version 6 (TCP/IPv6) and then click Properties.
- Select Use the following DNS server addresses. If there are any IP addresses listed in the Preferred DNS server or Alternate DNS server, write them down for future reference.
- Replace those addresses with the IP addresses of the Google DNS servers:
- For IPv4: 184.108.40.206 and/or 220.127.116.11.
- For IPv6: 2001:4860:4860::8888 and/or 2001:4860:4860::8844.
- For IPv6-only: you can use Google Public DNS64 instead of the IPv6 addresses in the previous point.
- Restart the connection you selected in step 3.
- Test that your setup is working correctly.
- Repeat the procedure for additional network connections you want to change.
For changing DNS of other operating system with Google, please visit this link
Likewise, you can find the setup steps for several DNS services on their official websites if you want to change the DNS servers of your network. It is highly recommended to replace your ISP’s DNS entry with a public DNS.
2. DNS Propagation
After changing DNS settings for a domain, we need to wait for a few hours for the DNS records to get updated, the technical term for this procedure is DNS propagation.
The problem is, the IP-Hostname table within the Domain Name System (DNS) is not updated instantly. It takes time for new domain registrations to propagate across the network. Practically, it can take a few hours for your domain to update its existence globally on every DNS servers to become accessible. You are always suggested to wait for at least 48 hours before contacting registrars, as you will get the same answer from them if you contact them before 48 hours. They always want to be on the safe side because in some cases it takes around 48 hours.
If you are very curious to know about the propagation status, you may use browser-based tools like DNS Propagation checker like DNS leaf. If it shows no error or just a couple of failures you should proceed with the solution given below. If it shows many false results then you need to wait for the DNS propagation to complete.
3. Check if the server is too occupied to handle the request.
Servers also give timeout errors if there is a sudden load hike on the server due to heavy traffic, sometimes it also happens due to DDoS(Distributed denial of service) attack. Change the servers IP temporarily if it is a DDoS attack.
Sometimes 504 gateway timeout error can appear when the website or the shared server on which your website is present is getting spammed using some malicious application also known as bots, which has the capability to flood your website with an abnormal number of requests per second, which can never be generated by humans and also cannot be served by our websites.
You can check the access logs of your websites and of the server too(if the server is dedicated to you). You will surely get some regular pattern of requests from the same IP or many IPs of the same subnet which will guide you to the culprits IP. You may also ask your hosting provider to block the IP or the complete subnet from which the unusual traffic is coming from.
4. Issue with CDN
If you are getting a timeout error while using a content delivery network, try disabling it. If the issue is with the content delivery network, you won’t get any timeout error after disabling the CDN. Which proves that the problem was with the content delivery network. You need to contact the CDN provider in such cases to resolve the issue.
5. The “.htaccess” file issue
The .htaccess file is present on the server using Apache web server. It is used for configuring various aspects of web pages like setting redirection, password and many other useful requirement can be implemented using a .htaccess file. You need to cross-check if this file is causing the issue. A misconfiguration of this file can produce timeout error. Please ensure taking a backup before modifying this file.
6. Proxy settings issue
To make sure that the timeout errors are appearing because of the proxy servers, not because of the web server, you need to check proxy settings on your client system. First, we need to check whether the proxy is configured on the browser level or the system level (using applications like Proxifier).
For example, here are the steps to check proxy settings for chrome browser
- Open Chrome and navigate to chrome://settings/
- Search for Proxy and click on “Open Proxy Settings”
3. Within the Connections tab, click LAN Settings
4. Untick the options that show “Automatically detect settings” and “Use a proxy server for your LAN” if either of them is enabled.
Steps to check proxy settings for Mozilla firefox browser
- Open your Mozilla browser and click on “Options” available on the top right corner.
- Scroll down to the bottom and click on “Settings”
- Select “no proxy” option on the top.
Steps to check proxy settings for MAC
- In your Apple menu, click on “System Preferences” and then click on Network.
- Select the network service you use in the list — for example, Ethernet or Wi-Fi.
- Click Advanced, then click Proxies.
- Uncheck any checked field.
If disabling the proxies resolve the issue of timeout errors then the problem was with the proxies. Please cross check your proxy settings or else contact your proxy provider.
7. Issue with WordPress Plugins
WordPress is developed using PHP (“Hypertext Preprocessor”, earlier it was known as “Personal Home Page”) all the plugins which work with WordPress are also designed in PHP to avoid compatibility issues. Unfortunately, there is one well-known issue with this one of the leading name in the world of CMS (content management system), it can only manage a limited number of requests. If a plugin is being used which is creating request more than limit which can’t be technically served will result in 504 gateway timeout error.
The real plugin causing the issue can be found by disabling the plugins one by one until the error stops, it is more like a hit and trial method.
8. Script bugs can cause timeout errors.
If proper coding is not done within the application, it can produce timeout errors. You can try locating the dirty code in your application by manually debugging it. You may also need to check the application logs, logs will surely guide you to the dirty code. Testing the application on a local machine in a private network is the best you can do without affecting the real code, you will surely get the dirty code causing the issue. You should use two different screens while testing the code, first for the testing and second for watching the real-time logs.
9. Database corruption issue.
Servers also give timeout errors if the database over which the website is operating is not optimized properly, or if it gets corrupted by any chance. In such cases, you need to repair and optimize your database. It is highly recommended to keep a backup of the databases before performing any repair or check.
There are multiple tools available for optimizing and repairing your corrupted database depending on the platform your website is running
The 504 gateway timeout error is very common, but it’s not very difficult to get rid of it. In most cases, you will get rid of it in seconds by following the easy steps that can be performed on the client side as discussed above. If you are lucky enough error will just go away after refreshing the page. If you are not able to fix the error with simple steps it is the right time for you to proceed with the Pro Steps.
After reading this blog, kicking out 504 gateway timeout error will be a child’s play for you. If nothing helps you need to contact your hosting provider for technical assistance.
Should you have any queries related to the 504 gateway timeout error. Write to us in the comments section below.