How to Fix 504 Gateway Timeout Error
While browsing the website, you will most likely come across a “504 Gateway Timeout Error”. In order to understand this error, one must understand how the Internet works. The Internet is a complex web of networks, meaning there are many web servers that act as a network to exchange information. These servers work in a chain that involves the process of getting the desired web page in the browser. In this chain process, one server upstream acts as a gateway for the downstream servers until it reaches the end of the final server 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 a 504 Gateway Error?
504 is an HTTP status code returned by an upstream web server when a request from a downstream server cannot be processed or takes too long. A 504 Gateway Timeout error basically means that the requested server did not get a response from the receiving server within the allotted time. This is often referred to as a “timeout,” a term you may have heard before. As you can imagine, these errors can appear in any browser, internet-connected application, or operating system.
The definition of this error is as follows:
Fix 504 Gateway Timeout Errors
Most of the time, unless your Internet connection or computer is experiencing problems, it will not normally time out. However, it is always worth making sure, and there are several ways to do this.
For Users:
- Reload the webpage
- Check the site later
- Restart your router/modem
- Check your network settings
- Contact the site owner
- Contact your ISP
For Site Owners:
- Check server logs
- DNS zone file updates (DNS propagation check)
- Firewall misconfiguration
- Incorrect CDN or cache settings
- Problems with PHP scripts
- Server connection delays
For WordPress Site Owners:
- Conflicts with plugin or theme files
- Enable debugging and inspections
- Set PHP execution time
If you see 502 – Bad Gateway, check out our separate article on how to fix the 502 – bad gateway error in Google Chrome.
Fix 504 Gateway Timeout Error for Users
1. Reload the Web Page
The quickest and easiest way to do this is to try reloading the web page and see if the error reappears. Even if the error isn’t on your end, the timeout could be temporary – perhaps due to a momentary influx of online traffic or something similar. If the error persists despite this, move on to the next option.
When you are on the payment gateway, remember not to refresh the page. Since the payment may have been successful before the timeout occurs, this may result in a double payment.
2. Check the site later
If reloading the site does not work, wait for a while and come back to the site later. The problem may be intermittent on the server side and may be resolved in a short time.
3. Restart your router/modem
Another quick and easy way is to try restarting all devices connected to the network. Nowadays, a router is a single device that has the function of both a modem and routing wireless connections. So if the problem is with your router, restarting the router may help resolve the 504 Gateway Timeout error. You can restart/reset the router by following the instructions that are usually pasted behind the device.
4. Check LAN settings
The network settings you should check is to disable the “Automatically detect settings” option in the LAN connection settings. Also, it is best to disable the proxy settings to check if the problem is occurring due to improper proxy settings.
5. Flush DNS and update IP and TCP/IP
If both the above options fail, you may need to flush DNS to avoid DNS cache issues. This will be helpful if you change the entire site or part of the site to a different server. Since your PC has old details in the cache, it may cause delays in getting the requested page. You can do this on Windows by referring to this article on how to view and flush DNS cache in Windows PC. You can also update IP and TCP/IP protocols using the following commands in the command prompt of Windows PC.
netsh winsock reset netsh int ip reset ipconfig /release ipconfig /renew
On Mac, go to the Terminal application and type the following command and press Enter.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
You should enter the administrator password to run this command.
6. Accessing blocked resources
Make sure you are not trying to access a site that is blocked by your ISP or country level. For example, if you live in a country like China, accessing a page with a Facebook share button will show a timeout error. This is because the service is blocked; you will see the placeholder for the social icon box showing a timeout error, although other content on the site will load.
You cannot do any tricks here, except using a reliable VPN or proxy to access blocked resources.
7. Contact your ISP
If any of the above methods still don’t solve the problem, try accessing another web page and see if the error reappears on another page. If the error also appears on other websites, it is best to contact your Internet Service Provider or check if there are any known outages or problems with your Internet connection.
8. Contact the Website Owner
If other pages open fine, then you can rest assured that it’s not your fault. If the error persists for more than a day or two, it’s best to contact the website/server administrator and notify them of the problem. Once notified, they may be able to fix it in a relatively short period of time, which means you can continue to use the website for your needs.
If the website/server administrator doesn’t contact you or fix the problem as quickly as possible, this is usually a sign that they’re not very reliable. The website may be a little, well… “dodgy”, in which case you can look for a different website that suits your needs.
For Website Owners:
If you’re the owner of a website and see a 504 Gateway Timeout error, there are different things you can do to restore your website.
8. Check the Server Logs
The first and important step is to check the log file on your server. Typically, this log file is located in the root directory of your site. If you can’t access the log file or can’t understand the contents, contact your hosting company.
9. DNS Zone File Updates
Similar to the DNS cache on your computer and browser, servers also have DNS zone file entries that resolve domain names to IP addresses. Modifying the DNS zone file may cause gateway timeout errors. If you have changed your DNS entries within the past few days, check the DNS propagation for your domain. This will show whether the site is accessible around the world using the new IP address.
Remember that changes in hosting servers and use of a CDN will result in changes in DNS servers. So if you have changed hosting companies automatically, the DNS servers will change to the new host, which can usually take up to 48 hours. While you will see DNS-related errors during this time, it can also cause timeout errors because it takes so long to resolve the new IP address.
10. Firewall Misconfiguration
Website owners often use firewalls to protect their sites from hackers. But sometimes a misconfiguration in the firewall settings can completely block resources and cause timeout errors. The easiest way to check this is to disable the firewall and test if your site is accessible. Learn more about dealing with firewalls in Windows and Mac.
11. Improper CDN or Cache Settings
Almost every site on the web today uses a CDN and cache. Server-side caching requires configuration changes, and CDNs like Cloudflare require DNS changes for caching.
If you suspect CDN or cache is the culprit, just disable them to check if the site can be opened. Then contact the service provider and set it up properly so that it does not affect real users.
12. Issues with PHP scripts
There are many PHP scripts that can be directly dropped into your server to get the desired functionality. These scripts can be purchased from third parties for almost no money. But the problem is that most of these scripts are poorly coded and will consume your server resources.
Hosting companies limit PHP execution time (like 300 milliseconds) so that these sites shut down the entire site or server. Once triggered, the script may run for a long time and cause a timeout error. The hosting company may also block or delete your hosting account as it will be against the terms and conditions. So, analyze the log files on your server and check for PHP scripts causing timeout errors. If yes, immediately remove or disable these scripts and discuss this with the service provider.
13. Server Connection Delays
Typically, if you use a shared hosting server, you will have slow page load times. In this case, resource-intensive pages on any site hosted on the same server can slow down the entire server and cause timeout errors. Check server utilization if you have access or contact your hosting provider to arrange more resources for your site through upgrades.
For WordPress Site Owners:
If you have a WordPress content management system, then the situation may be very different. Here are some options you can try:
14. Conflicts with Plugin or Theme Files
Did you update one of your themes or plugins before receiving the 504 Gateway Timeout error? If yes, revert to a previous version and check if the site is accessible. Check out this post to learn how to revert plugin updates and restore your site. If you can’t find a specific plugin that’s causing the problem, disable all plugins and revert to a default WordPress theme. This should help access the problem without plugins and narrow down the issue. It’s also a good idea to put your site in maintenance mode until you fix the problem.
15. Enable debugging and inspections
WordPress allows you to debug errors for troubleshooting purposes. You can enable debugging by editing the “wp-config.php” file and add a line at “/* That’s it, stop editing! Happy publishing. */”.
define( 'WP_DEBUG', true );
Once enabled, you will see 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. Keep in mind that all users who open your site will also see the error messages. Therefore, for security reasons, it is recommended to debug in a staging or testing environment instead of live.
16. Set PHP execution time
As we have already explained, PHP scripts may cause delays due to execution time limits set by your host. If you are sure, increase the execution time by adding the following line in your “php.ini” file.
max_execution_time = 300
Before modifying it yourself, make sure your host allows this limit.
Conclusion
Whether you are a user or a website owner, you may feel frustrated if you cannot quickly resolve such errors. Also remember that the 504 Gateway Timeout Error is different from the 502 Gateway Error. We believe that one of the above steps can help you solve the problem.