Everyone that uses the Internet has likely experienced a “504 Gateway Timeout Error”. In order to understand this error, it is essential to understand how internet works. Internet is a complex web of web means there are lot of web servers exchanging information as a network. These servers work in a chain involved in the process of getting required webpages on your browser. In this chain process one server at the upstream acts as a gateway for the downstream server till the end of the final server is reached where the requested information can be obtained.
What is 504 Gateway Error?
504 is HTTP status code returned by the upstream web server when the request from downstream server can’t be processed or taking too long time. The 504 gateway timeout error basically means that the requested server didn’t get a response from the receiving server on the other side within the stipulated timeframe. This is often referred to as a “Time Out”, which is a terminology that you have likely heard of before. As you can imagine, these errors can appear in any browser, internet linked application or operating system.
The definition of this error is as below:
When the server1 is acting as an external gateway or proxy and did not receive the response on time from the next server2 further up in the request chain which it tried to access in order to fulfill the request then code “504 – Gateway Timeout” is received.
If you are seeing 502 – Bad Gateway, check out separate article on how to fix 502 – bad gateway error in Google Chrome.
Fixing 504 Gateway Timeout Error for a User
Reload the Webpage
The quickest and simplest way is to try and reload the webpage, to see if the error occurs again. Even if the error isn’t on your end, the time out may have been temporary – possibly due to a momentary influx in online traffic, or something similar. If the error persists in spite of this, move on to the next option.
Check the Site Later
If the reloading of the site does not work then wait for sometime and come back to the site later. The problem could be intermittent at the server side which may get resolved in short time.
Restart Router / Modem
Another quick and easy method would be to try and restart all of your devices linked to the network. Nowadays the router is a single device does both the function of modem as well as routing the wireless connection. So restarting the router may help in resolving the 504 gateway timeout error, if the problem is at your router.
Check LAN Settings
The network setting you should check is to disable “automatically detect settings” option in your LAN connection settings. Also it is a good idea to disable proxy settings to check whether the issue occurs due to improper proxy settings.
Flush DNS and Renew IP and TCP/IP
Failing both of the above options, you might want to flush your DNS to avoid the DNS caching issues. This will help especially if the complete site or part of the site is changed to the different server. Since your PC has the old details in the cache, it may cause delay in getting the requested page.
You can do this on Windows 10 by referring this article on how to view and flush DNS cache in Windows 10. You can also renew the IP and TCP/IP protocol by using the below commands on the command prompt of your Windows 10 PC.
On Mac, go to the “Terminal” app and type the following command and hit enter.
You should enter the administrator password in order to run this command.
Accessing Blocked Resources
Ensure you are not trying to access the sites that are blocked by the ISP or at country level. For example, accessing the pages with Facebook follow buttons may take long time in China. This is because the service is blocked; though the other content on the site will load you will see the placeholder of the social icons box showing timeout error.
You can’t do any tricks here other than using reliable VPN or proxy to access the blocked resources.
Contact Your ISP
If any of the above still isn’t fixing the problem, try visiting another webpage to see if the error is reoccurring on another page. If the error is popping up on other websites as well, it might be a good idea to contact your internet service provider, or check if there are known outages or problems with your internet connection.
Contact Website Owner
If other webpages are opening fine, then you can rest assured that it isn’t caused by anything on your end. If the error continues for much more than a day or two, it would be a good idea to contact the website/server administrator, and notify them of the problem. Once notified, they may be able to fix it within a relatively small timeframe, meaning that you can go about using the website to your hearts content.
If a website/server administrator doesn’t either contact you back or fix the problem as promptly as possible, it’s usually a good sign that they aren’t very reliable. The website may be a little, well… “dodgy”, in which case, you wouldn’t be wrong to have a look for a different website to suit your needs.
For a Website Owner:
If you are the owner of a website and seeing 504 gateway timeout error, there are different actions you can perform to recover the site.
Check Server Log
The first and important step is to check the log file on your server. Generally this log file is located in the root of your site. Get in touch with your hosting company, if you can’t access the log file or can’t understand the content.
DNS Zone File Update
Similar to DNS cache on your computer and browser, the server also has DNS zone file entries to resolve the domain name into an IP address. There are possibilities that modification in the DNS zone file may result in gateway timeout error.
If you have changed the DNS entries within past few days then check the DNS propagation for your domain. This will show whether the site can be reachable all over the world using the new IP address.
Remember change in hosting server and use of CDN will result in change in the DNS servers. So if you have changed the hosting company automatically the DNS servers will get changed to the new hosting which may take up to 48 hours time in general. Though you will see DNS related errors during this time, it can also cause timeout error due to long time taken to resolve the new IP addresses.
Misconfiguration of Firewall
It is common among site owners to have firewall to protect the site from hackers. But sometimes the misconfiguration in firewall setup will block the resources completely and result in timeout error.
The easies way to check this is to disable the firewall and test whether your site can be accessible.
Improper CDN or Caching setup
Almost every site on the web uses CDN and caching nowadays. Server side caching needs a configuration changes and also the CDN like Cloudflare needs DNS changes for caching.
If you suspect CDN or caching is the culprit, just disable them to check the site can be opened. Then contact the service provider and setup properly so that it will not affect the real users.
Problem with PHP Scripts
There are plenty of PHP scripts that can be just dropped into your server to get the required functionalities. These scripts can be purchased from third parties for little to no money. But the problem is that most of these scripts are poorly coded and occupy your server resources.
The hosting companies restrict the PHP execution time (like 300 milliseconds) so that these sites are taking down the whole site or server. When triggered, the script may run for a long time and result in timeout error. The hosting company may also block or delete your hosting account, as this will be the breach in the terms and conditions.
So analyse the log file on your server and check the PHP scripts cause the timeout error. If yes, remove or disable those scripts immediately and discuss with the service provider on this.
Delay in Server Connection
Generally the loading time of your pages will be very slow, if you are using shared hosting server. In such case, the resource intensive pages on any of the site hosted on the same server may slow down the complete server and result in timeout error.
Check the server utilization if you have access or get in touch with your hosting provider to arrange more resources for your site by means of upgrading.
For WordPress Site Owner:
If you have a WordPress content management system then the situation could be much different. Here are some of the options you could try:
Conflict with plugins or theme files
Did you update your theme or one of the plugin just before getting the 504 gateway timeout error? If yes, revert back to previous version and check the site is accessible.
If you could not find a specific plugin, disable all plugins and revert back to default theme. This should help in accessing the without plugins and narrow down the issue.
Enable Debug and Check
Edit your “wp-config.php” file and add the below line to enable debugging.
When enabled, you will be seeing the relevant error message on your site.
Remember all users opening your site can also see the error message. So it is recommended to do the debugging on stagging or testing environment instead of live site for security reasons.
Set PHP Execution Time
As we have already explained the PHP scripts can cause delay due to execution time limit set by your host. If you are sure, increase the executing time by adding the below line in “php.ini” file.
Ensure your host allows the limit before modifying on your own.