While browsing websites, you most 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 in 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.
Learn how to fix err_connection_reset, err_internet_disconnected, err_network_changed and err_connection_closed errors in Google Chrome.
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.
Fix 504 Gateway Timeout Error
Most of the time, unless you have been having difficulties with your internet connection or computer, the time out isn’t typically on your end. However, it always pays to make sure, and there are several ways to do so.
For a user:
- Reload the webpage
- Check the site later
- Restart router / modem
- Check your network settings
- Contact website owner
- Contact your ISP
For a site owner:
- Check server log
- DNS zone file update (DNS propagation check)
- Misconfiguration of Firewall
- Improper CDN or Caching setup
- Problem with PHP script
- Delay in server connection
For WordPress Site Owner:
- Conflict with plugins or theme files
- Enable debug and check
- Set PHP execution time
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
1. 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.
Remember not to refresh the page when you are on payment gateway. This may result in double payment due to the fact the payment might have been successful before the timeout happens.
2. 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.
3. 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. You can follow the instructions, generally pasted behind the device, to restart / reset your router.
4. 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.
5. 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 by referring this article on how to view and flush DNS cache in Windows PC. You can also renew the IP and TCP/IP protocol by using the below commands on the command prompt of your Windows PC.
netsh winsock reset netsh int ip reset ipconfig /release ipconfig /renew
On Mac, go to the “Terminal” app and type the following command and hit enter.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
You should enter the administrator password in order to run this command.
6. 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 share buttons will show timeout error if you are living in countries like China. This is because the service is blocked; though 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.
7. 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.
8. 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 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 websites 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.
8. 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.
9. 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.
10. 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 easiest way to check this is to disable the firewall and test whether your site can be accessible. Learn more about handling firewall in Windows and Mac.
11. 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.
12. 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 consume 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, analyze 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.
13. 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:
14. Conflict with Plugins or Theme Files
Did you update your theme or one of the plugins just before getting the 504 gateway timeout error? If yes, revert back to previous version and check the site is accessible. Check this article on how to revert back plugin update and restore your site. If you could not find a specific plugin causing issue, disable all plugins and revert back to default WordPress theme. This should help in accessing the issue without plugins and narrow down the issue. It is also a good idea to put your site under maintenance mode till the time you fix the problem.
15. Enable Debug and Check
WordPress allows you to debug errors for troubleshooting purposes. You can enable debugging by editing your “wp-config.php” file and add the below line of code just before the line saying “/* That’s all, stop editing! Happy publishing. */”.
define( 'WP_DEBUG', true );
When enabled, you will be seeing relevant error messages on the frontend of your site. You can analyze the errors to understand the root cause of the problem and work on fixing it. Remember all users opening your site can also see the error message. So, it is recommended to do the debugging on staging or testing environment instead of live site for security reasons.
16. 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.
max_execution_time = 300
Ensure your host allows the limit before modifying on your own.
Conclusion
Whether you are a user or site owner, this type of errors may frustrate you if you can’t resolve it quickly. Also remember, 504 gateway timeout error is different than 502 bad gateway. We believe one the above steps helped you to resolve the issue.
Leave a Reply
Your email is safe with us.