Find answers, guides, and tutorials to supercharge your content delivery.

HTTP Status Code 504 Gateway Timeout

Updated on October 4, 2018

What is the meaning of a 504 Gateway Timeout error?

A 504 Gateway Timeout indicates that the proxy/edge server did not get a response from the upstream/origin server in a given time window. KeyCDN does not respond with a 504 error but sends a 500 Origin Not Reachable. The image below shows at what point 504 Gateway Timeout errors occur in the HTTP cycle.

What can cause a 504 error?

If you are not the website owner of a page which is returning a 504 Gateway Timeout error, it usually isn't your problem to fix. Most of the time it must be dealt with by the people who set up the network at the site that hosts the web server. That being said, the following are two possible reasons for a 504 Gateway Timeout error to occur.

  • 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 a 500 Origin Not Reachable from KeyCDN).
  • The origin server is down or not working properly.

How you might see a 504 Gateway Timeout error

Different web servers may show different variations of the 504 Gateway Timeout error. Although they all mean the same thing, their naming conventions may slightly differ. The following displays a few examples of how you might see a 504 error.

  • 504 Gateway Timeout
  • HTTP 504 Gateway Timeout
  • HTTP 504 Error
  • HTTP 504
  • 504 Gateway Time-Out
  • Nginx 504 Gateway Timeout
  • Gateway Timeout (504)
  • 504 Gateway Timeout NGINX

Although an Nginx timeout or HTTP 504 error can occur for a few reasons, the following section outlines a couple of 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 visitor of a web page, 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 by the time 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.
  • 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.

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 and if not, a traceroute test will help you determine where in the packet's path there was an issue. 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

If your web server is running on Nginx and you are receiving and 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 are using Nginx as a proxy then 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) then 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.

KeyCDN uses cookies to make its website easier to use. Learn more about cookies.