Understand the the HTTP 504 Gateway Timeout error: What are the causes and how to fix it.
Table of Contents
- What is the 504 Gateway Timeout error?
- Identify your error scenario
- 504 Gateway Timeout causes
- How to fix the 504 error when your computer is behind a proxy
- How to fix the 504 error when your website is behind a proxy
- All HTTP Status Codes
What is the 504 Gateway Timeout error?
The HTTP 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.
504 Gateway Timeout vs 499 Client Closed Request
This 504 error is similar to the 499 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 Gateway Timeout
- Nginx 504 Gateway Timeout
- 504 Gateway Timeout NGINX
- HTTP 504
- 504 ERROR
- Gateway Timeout (504)
- HTTP Error 504 – Gateway Timeout
- Gateway Timeout Error
Identify your error scenario
There are two different situations where a 504 error can occur:
- Your computer is behind a proxy service. You can get 504 errors 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).
504 Gateway Timeout causes
We will group the error causes depending on previous proxy usage cases.
504 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 error when your computer is behind a proxy
You can follow the next steps to find and fix the 504 Gateway timeout 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 find out whether or not your computer is behind a proxy server you can follow the instructions of this: How to know if you are using a proxy server
Check the computer proxy settings
To fix the 504 Gateway Timeout Error caused by your computer, check the proxy server settings and make sure they’re correct.
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 error persists, the next step is to ask your proxy service provider.
How to fix the 504 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:
- Cloudflare status page
- Sucuri status
- KeyCDN status
- StackPath status
- Google cloud services status
- Amazon Cloudfront status
Check if you have time-consuming requests
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!To clone a WordPress site with Wetopi is as easy as a simple click.
Staging environments are the solution!
We are techies passionate about WordPress. With wetopi, a Managed WordPress Hosting, we want to minimize the friction that every professional faces when working and hosting WordPress projects.
Not a wetopi user?
Free full performance servers for your development and test.
No credit card required.
All HTTP Status Codes
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
208 Already Reported
226 IM Used
300 Multiple Choices
301 Moved Permanently
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
308 Permanent Redirect
402 Payment Required
404 Not Found
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
411 Length Required
412 Precondition Failed
413 Payload Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
418 I’m A Teapot
421 Misdirected Request
422 Unprocessable Entity
424 Failed Dependency
426 Upgrade Required
428 Precondition Required
429 Too Many Requests
431 Request Header Fields Too Large
444 Connection Closed Without Response
451 Unavailable For Legal Reasons
501 Not Implemented
505 HTTP Version Not Supported
506 Variant Also Negotiates
507 Insufficient Storage
508 Loop Detected
510 Not Extended
511 Network Authentication Required
599 Network Connect Timeout Error