How to Fix 504 Gateway Timeout Error in NGINX

Users get 504 Gateway Timeout Error in NGINX when you use it as a reverse proxy server and it gets timed out waiting for a response from back end web servers. Here’s how to fix 504 Gateway Timeout error in NGINX.

 

What is 504 Gateway Timeout Error in NGINX

When you use NGINX as reverse proxy server and it times out waiting for a response from back end web servers, it sends a 504 Gateway Timeout error to client browser. This can happen due to various reasons such as application bugs, faulty plugins, poorly configured modules. Sometimes, it may be due to network issues and may get fixed automatically.

Bonus Read : How to Fix 502 Bad Gateway Error in NGINX

 

How to Fix 504 Gateway Timeout Error in NGINX

Here are some of the key ways to fix 504 Gateway Timeout Error in NGINX.

 

1. Server goes down

One of the most common causes for 504 bad gateway is that your back end server has gone down because it got overloaded with too many requests, or some long running requests. Such issues get fixed automatically when server  load gets balanced. However, analyze server logs to identify the requested URLs just before your server went down, to optimize their code. Sometimes, it may also be a signal that you need to upgrade your server.

 

2. DNS issue

DNS issue can be on client side or server side. In case of server side DNS problems, the issue may be because your domain name doesn’t resolve to an IP, in case you have changed your website IP address or migrated your website to a new IP. In such cases, it may take anywhere between 5 minutes to 24 hours for the DNS records to be updated.

In case of client-side problems, try flushing local DNS cache.

Bonus Read : How to Increase Request Timeout in NGINX

 

3. Disable CDN

If your website uses CDN, it may sometimes timeout causing NGINX to return 504 Gateway Timeout error. In such cases, just disable your CDN and try accessing your website.

 

4. Network Connectivity

NGINX will also give 504 Gateway Timeout error if there are network connectivity issues between your reverse proxy server and back end web server. Log into your proxy server and try connecting to your web server using curl/ping command.

Bonus Read : How to Increase File Upload Size in NGINX

 

5. Firewall Issues

If your web server’s firewall is not properly configured it may block many requests causing NGINX to give 504 Gateway Timeout error.

 

6. Spams, Bots and DDOS attack

Sometimes malicious attackers may flood your web server with too many requests, or slow running requests. Monitor your server log to see if there is any spike in traffic, identify their IP address ranges and put measures in place to regulate their incoming requests.

Bonus Read : How to Hide NGINX Server Version From Header

 

7. Bugs and Faulty Plugins

Sometimes application bugs, faulty plugins and poorly configured modules can also slow down or bring down your server, causing NGINX to return 504 Gateway Timeout error. In this case too, you need to analyze server logs to find out which requested URLs are causing the issue and fix them soon.

 

 

Hopefully, the above tips will help you fix 504 Gateway Timeout Error in NGINX.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!