November 25, 2019
4 min Read
November 25, 2019
4 min Read
504 gateway timeout is one of the HTTP status codes that a server can send back when it was unable to complete a request. While it is less frequent than 500 internal server error or 502 bad gateway error, everyone has encountered it at least a couple of times while browsing the internet. Hence this guide focuses on what 504 gateway timeout error is and how to fix it in WordPress.
When you visit any website, it generates requests and sends them to web servers that hold the required elements. Each time a request is handled, the server sends back an HTTP status code with the requested resources. By default, the HTTP status code is not displayed unless something went wrong in the process.
HTTP status codes beginning with the digit “5” are server-side errors. They pop up whenever it’s impossible to complete a request due to a miscommunication between several servers.
504 gateway timeout error is an HTTP status code which appears when one server does not receive a timely response from another server that acts as a gateway or proxy. In short, it means the server was unable to complete your request within the given time frame.
504 Gateway Timeout nginx
Gateway Timeout Error
HTTP Error 504
504 Gateway Time-out – The server didn’t respond in time
HTTP Error 504 – Gateway Timeout
While in most situations the cause of 504 gateway timeout errors come from the server-side, they may also pop up due to issues or misconfigurations from the user-side. Thus, we’ll go through the basic troubleshooting steps with both options in mind. Part of the solutions are suitable for WordPress, but most of them can be applied to any website.
The first step to troubleshoot 504 gateway timeout error is the simplest one. Wait a couple of minutes and refresh the page. It might be that the server is receiving more requests than usual at the time and is unable to handle more.
While you wait, you may use online tools that check if the website is down. It’s a great way to confirm whether the problem is related to the local network.
In case the website is up, but you still see the 504 gateway timeout error, try changing up your browser to a different one. Clearing browser cache or using incognito mode can also help verify if the issue browser related.
504 gateway timeout can sometimes be a result of incorrect or outdated DNS cache, but it is not hard to clear it. The way of doing it differs depending on your operating system. Here’s a tutorial on how to flush DNS on Windows, Linux, and Mac OS.
Temporary switching the DNS server to Google Public DNS can let you rule out if the HTTP status code appears due to a DNS problem. Though we mostly recommend this option for advanced users.
Try loading the website on a different computer, network connection, or a mobile phone. In case none of the above solutions fixed the 504 gateway timeout error, this step will let you confirm if it is a local issue or a server-side problem.
The 504 gateway timeout error may also be a cause of recent website changes or updates. The quickest way to find out is by checking the error log for any hints. WordPress users can enable error message logging by adding the following lines to the wp-config.php file:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
Once done, all generated entries will appear in wp-contents/debug.log file.
While troubleshooting a 504 gateway timeout error, it’s advisable to look through your website plugins and extensions. In WordPress, plugins related to caching can be the culprit. Outdated or incompatible plugins may also cause problems. Hence disabling all of them temporarily will let you know if you’re digging in the right place.
To disable all WordPress plugins, navigate to the wp-content directory and give the plugins folder a different name.
If your site works fine when all plugins are off, the next step would be to locate which one causes the HTTP error 504. Rename the plugins directory back to its original name and this time try to disable them individually.
If you’re utilizing a CDN to serve content faster, you should check if everything is okay from that side. One of the most frequently used solutions is CloudFlare, which acts as a CDN and a DDoS mitigation service. While using it, you can encounter two version of the 504 gateway timeout error.
The following version of 504 error appears when the issue is on CloudFlare’s side. The best approach is to contact CloudFlare support or disable it entirely. However, if you turn it off, you may have to wait a couple of hours for the DNS to propagate.
If you’re using VPS hosting, there are a few extra things you can try to fix the 504 gateway timeout error. They would involve tweaking the server settings and increasing specific resource limits.
Apache users may increase the default timeout value in the httpd.conf file. For example:
# Timeout: The number of seconds before receives and sends time out. Timeout 600
Furthermore, increasing the max_execution_time limit in php.ini can also bring positive results:
Save the changes, restart apache, and re-check. The 504 gateway timeout error should be gone if the cause was insufficient request timeout value.
If your VPS utilizes Nginx, try increasing the following values in /etc/nginx/conf.d/timeout.conf:
proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600;
It’s also advisable to increase the max_execution_time in php.ini:
Once the changes are saved, restart Nginx and try to reach the website again.
In case the 504 gateway timeout error persists after following all the above solutions, it’s advisable to contact the web hosting support staff. Try to describe what steps you took to troubleshoot the issue and provide as much information as possible to speed up the process.
In this guide, we’ve look over the common steps to troubleshoot and fix a 504 gateway timeout error. If you have any tricks, tips, or extra solutions for fixing this HTTP status code, let us know if the comments below!
July 16, 2018
You are a life saver! This pesky 504 message kept bugging my site for such a long time. My host had no clue what happened. I started investigating my error log as you suggested and found out that a few WordPress plugins created many error entries. After deleting these plugins, my website works perfectly. No more error now. It seems like Hostinger has a solution for everything. I'm starting to consider moving my website to you guys haha!
Replied on July 18, 2018
I'm glad to hear you were able to fix your website. And the doors of Hostinger are always open for you, Rajma! ;)
December 04, 2018
Spell check strikes again.... in the 'conclusion', the word overlooked needs an edit. Either change it to read that you have looked over, looked at, or considered, etc. BTW, your article is extremely helpful. Well done!
Replied on January 14, 2019
Fixed, thank you for the catch! ;)