Last updated on August 10th, 2020 at 03:05 am
504 Gateway Timeout Error occurs in Apache when it is acting as a proxy server and times out while waiting for a response from back end web servers. Here’s how to fix 504 Gateway Timeout error in Apache.
What is a 504 Gateway Timeout Error in Apache
When you use Apache as proxy server to direct incoming requests to one or more back-end web servers, sometimes it might timeout while waiting for a response from a web server. In such cases, Apache will give a 504 Gateway Timeout error. It can occur due to various reasons such as application bugs, faulty plugins, etc. Basically, the Apache proxy server keeps waiting for a response from the web server, and since it doesn’t receive a response even after a long time, it times out.
Bonus Read : How to Check Which Apache Modules Are Enabled
How to Fix 504 Gateway Timeout Error in Apache
Here’s how to fix 504 Gateway Timeout error in Apache
1. Server is Down
One of the most common reasons for 504 Gateway Timeout error is that the back end server is unreachable, since it is down for maintenance, or because it is overloaded with requests.
In such cases, website visitors can simply refresh the page to see if it starts working again.
Bonus Read : How to Fix 502 Bad Gateway Error in Apache
2. DNS Issue
DNS issue can happen on server-side or client side. In case of server side DNS problems, it may be because your domain name doesn’t resolve to an IP. This can happen if you have changed your IP address or migrated your website to a new IP. Depending on TTL value of DNS records, it can take anywhere from 5 minutes to 24 hours.
On client side, it can be fixed by flushing your local DNS.
3. Disable CDN
If your website uses CDN service, then sometimes the CDN may have issues causing Apache to return 504 Gateway Timeout error. In such cases, simply disable your CDN and see if it works.
Bonus Read : How to Speed Up Apache Web Server
4. Upgrade Server
If your back end server is overloaded, it can result in 504 Gateway Timeout, since it won’t be able to respond to incoming requests, causing them to timeout. In such cases, find out if you need to upgrade your server to a more powerful configuration to fix 504 gateway timeout error in Apache.
5. Network Connectivity
Apache will also give 504 Gateway timeout even if there are network connectivity issues between proxy server and web server. Log into your proxy server’s host and try connecting to web server via curl or ping command.
Bonus Read : How to Increase Request Timeout in Apache
6. Firewall Issues
If your website firewall is not properly configured, it can prevent proper connection and result in this error. So check your firewall logs to see if there is any sudden spike in request blockages.
7. Spams, Bots, DDOS attack
Sometimes malicious attackers can bring down your web server by sending too many requests to it, or by sending really slow requests to it. Monitor your traffic to see if there is an spike. Enable mod_evasive in Apache to automatically block spam, bots and DDOS attack, and fix 504 Gateway Timeout error in Apache.
8. Faulty plugins or Buggy Code
Sometimes faulty/poorly configured plugins or buggy code can slow down or bring down your web server, causing your Apache proxy to return 504 Gateway Timeout. In this case, you will have to analyze server logs to find out which requested URL is causing this error and fix it accordingly.
Hopefully, the above tips will help you fix 504 Gateway Timeout Error in Apache web server.
Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.