Fixing a 504 Gateway Timeout Error
One of the most common HTTP 5xx errors that website visitors and operators face is the 504 Gateway Timeout
. If you are a website owner, you know how important it is to fix such server errors as soon as possible. A web page failing to load negatively affects the user experience, and your visitors may move on to the competition.
It is bad enough to receive an error message. It is also laborious that the 504 Gateway Timeout
error will not tell you why it occurred. This makes it challenging to figure out the reason for the server timeout. We will help you find out how to diagnose its cause and fix it afterward.
What is the meaning of a 504 Gateway Timeout error?
A 504 Gateway Timeout
occurs when two servers are involved in processing a request, and the proxy/edge server has not received a response from the upstream/origin server within a specified time window. The image below shows when 504 Gateway Timeout
errors occur in the HTTP cycle.
What can cause a 504 error?
It is usually not your problem to fix if you are not the owner of a site that returns a 504 Gateway Timeout
error. As we know, the 504
error is due to a timeout between servers, and in most cases, the people who set up the network at the site hosting the web server have to take care of it. Thus, the problem is probably not due to the Internet connection or the device. However, there are two possible reasons for a 504 Gateway Timeout
error.
- A silent firewall drop. A firewall reject would cause a reset and immediately terminate the connection. The edge server would return a
502 Bad Gateway
(or a500 Origin Not Reachable
from KeyCDN). - The origin server is down or not working properly.
How you might see a 504 Gateway Timeout error
Websites and web servers can each customize how they display the 504 Gateway Timeout
error to their users. Although they all mean the same, their naming conventions may slightly differ. For example, KeyCDN does not respond with a 504
error but sends a 500 Origin Not Reachable
.
In the following listing, examples of how a 504
error is displayed:
- 504 Gateway Timeout
- HTTP 504 Gateway Timeout
- HTTP 504 Error
- HTTP 504
- HTTP 504
- 504 Error
- 504 Gateway timeout
- Nginx 504 gateway timeout
- Gateway timeout (504)
- 504 Gateway Timeout NGINX
- This page is not working - domain took too long to respond
- 504 gateway timeout - server did not respond in time
- The page request was aborted because it took too long to respond
- Site visitor: There was a problem processing your request. Please try again in a few minutes.
- Site owners: There was a timeout at the gateway. You should check your error log for more information.
- A blank white screen
Although an Nginx timeout or HTTP 504
error can occur for a few reasons, the following section outlines a few things you can check to help solve the error.
How to solve a 504 HTTP error from a visitor's perspective
As mentioned above, as a web page visitor, a 504
error is likely not caused by your device or network connection. However, as a visitor, you can begin with the following suggestions on how to solve a 504 Gateway Timeout
error.
- Simply try refreshing the page that is experiencing the error. The error may only be temporary and could be resolved when you refresh.
- Try again later. The web administrators of the particular page are likely working on resolving the issue. Try reloading the page at a later time to see if the issue has been resolved.
- Furthermore, you can load the web page in a different browser to exclude this as a problem. Since most
504
errors are due to temporarily overloaded servers, this step should result in your website returning immediately. - Restart your network devices and try using a different DNS server such as Google's free public DNS to help troubleshoot if the issue is on your end.
- Unless all of this helps, you can check to see if a website is down for everyone or just for you. A useful online tool for testing a website for downtime is Down for Everyone or Just Me.
How to solve a 504 HTTP error from an admin's perspective
To start troubleshooting the 504
HTTP error as a website or server administrator, you can begin with the following suggestions:
- Verify if the FQDN (fully qualified domain name) resolves to the right IP address (DNS Checker).
- Also, check the load on the server or if there are errors in the logs.
Another great way to troubleshoot a 504 Gateway Timeout
error is to perform a ping or traceroute on the origin server. This will help you determine if the origin server is reachable. If not, a traceroute test will help you determine where there was an issue in the packet's path. You may also run a traceroute from the origin server to your IP to see if there is a communication problem on the way back. Read our detailed article for more information about the traceroute command.
Nginx 504 - Timeout error
One of the most common reasons for a 504 Gateway Timeout
error is a server problem. If your web server is running on Nginx, for example, and you are receiving an Nginx 504
error, then you can try increasing a few of your config settings.
Fixing an Nginx 504 Gateway Timeout error using Nginx as a proxy
If you use Nginx as a proxy, you need to increase the Nginx timeout values in your nginx.conf
file. To do so, add the following directives:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
Once the Nginx timeout values are added and saved, reload your Nginx server service nginx reload
.
Fixing an Nginx 504 Gateway Timeout error using Nginx and FastCGI
If you are using Nginx in combination with FastCGI (PHP-FPM), you will need to make a couple of changes to your PHP-FPM, php.ini
, and your nginx.conf
file.
For your PHP-FPM file changes navigate to /etc/php5/fpm/pool.d/www.conf
(this may be a different path depending on your PHP version). Once you have opened this file, set the following directive:
request_terminate_timeout = 300
Next, you must navigate to your php.ini
file located at /etc/php.ini
. Search for the max_execution_time
directive. If this is already set, increase the value to 300
, if the directive is not already present, add it as follows:
max_execution_time = 300
Finally, modify your nginx.conf
file to increase the fastcgi_read_timeout
directive. The following example will apply this setting to all sites on the Nginx server, however this can also be modified to be site-specific.
http {
...
fastcgi_read_timeout 300;
...
}
Once complete, simply reload Nginx service nginx reload
as well as PHP-FPM service php5-fpm reload
.
Summary
In this article, you have learned what causes 504 Gateway Timeout
errors can be attributed to and what methods you can use to fix the error. Usually, these errors are caused by server-side problems. In this case, we recommend contacting your host and getting it fixed quickly.