What is the status code 504 Gateway Timeout error?
The status code 504 Gateway Timeout error occurs when an intermediary server, or rather a network interface, cannot respond to the browser’s request within a specified time.
This intermediary server or network interface can be a service acting as a security filter, a performance cache service, a Load Balancer, etc. This is what we call a “proxy” acting as a network gateway for your computer or for your web server traffic.
Sample schema where an Nginx Load Balancer can’t wait more and closes the connection showing a Status Code 504 Gateway Timeout Error.
504 Gateway Timeout vs 499 Client Closed Request
This Status Code 504 HTTP error is similar to the 499 status code error that Nginx produces. The difference is that, when you get a 499, it is the client that closes the connection whereas with a 504 it is the proxy server that closes the connection.
Different 504 error messages
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
Nginx 504 Gateway Timeout
504 Gateway Timeout NGINX
HTTP 504
504 ERROR
Status Code 504 Gateway Timeout Error
Gateway Timeout (504)
HTTP Error 504 – Gateway Timeout
Gateway Timeout Error
Identify your 504 HTTP error scenario
There are two different situations where a 504 HTTP error can occur:
Your computer is behind a proxy service. You can get Status Code 504 while browsing when your network traffic is passing through an intermediate proxy service. This is common in big companies and in some Internet providers in order to add a layer of security and/or to reduce the network traffic.
Your application or website is behind a proxy service. You get the error 504 only while browsing a determined website. In this case, the site throwing the error does have a proxy server acting as a Firewall, Load Balancer, or CDN (Content Delivery Network).
Status Code 504 Gateway Timeout causes
We will group the error causes depending on previous proxy usage cases.
504 http error causes when your computer is behind a proxy
Incorrect computer proxy settings can cause 504 errors.
Problems in the proxy service your computer is using.
Problems with your Internet service provider.
504 error causes when your website is behind a proxy
Your external Proxy service is failing.
Your website or app hangs.
Your Proxy has a low timeout.
How to fix the 504 http error when your computer is behind a proxy
You can follow the next steps to find and fix the Status Code 504 error when your local computer is working behind a proxy service:
Proxies provide an additional layer of security for your computer or mobile device and can also cache the websites you go to so that they load faster upon subsequent visits.
To fix the 504 Gateway Timeout Error caused by your computer, check the proxy server settings and make sure they’re correct.
This is the Mac OSX Proxy setup page you can find in the Network Configuration panel.
If your proxy setup is ok, chances are that there is a problem with the proxy service.
Check your network connectivity and proxy status
If your computer proxy settings are ok, then first of all: reboot your network modem and WiFi router. This will ensure we start with a “clean network connection setup”.
If your 504 http error persists, the next step is to ask your proxy service provider.
How to fix the status code 504 http error when your website is behind a proxy
In this case, you get the error 504 only while browsing a determined website. If this site is under your administration, follow the next solutions:
Check the Proxy service status
If you are using an external proxy service, check the status service page of this service.
This is a list of “Status Pages” of main providers of Load Balancing, CDN, and Security services:
You can have 504 errors due to a slow web server If the time spent processing and building your web page takes more time than the proxy gateway can wait.
In this previous log screenshot, you can observe that 504 errors have a “request_time” greater than 300 seconds. This is a clear case of pages with an excessive processing time. If this is your case, try one or more of these fixes:
In this sample case, 300 seconds is a reasonable waiting time. But, if waiting longer in the proxy makes sense for your affected requests: increase the timeout in your proxy.
If waiting longer does not solve the problem or it’s not an option: Increase the processing capacity of your server. By increasing the “processing power”, you will reduce the waiting time of your proxy service.
Something you should never dismiss is to try to find out if there is a code or database problem:
Look for errors in log files.
Repair and/or optimize tables and indexes. If you are running MariaDB or MySQL, chances are that you have a phpMyAdmin panel:
If your site is running with WordPress, try to find plugin conflicts with excessive CPU or database usage. To do this, we recommend you debug your WordPress with Query Monitor plugin.
Do not break your production site! Staging environments are the solution!