EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Nginx Tutorial Nginx Gateway Timeout
Secondary Sidebar
Nginx Tutorial
  • Basic
    • Nginx Add_header
    • Nginx FastCGI
    • Nginx WAF
    • Nginx Forward Proxy
    • Nginx Ingress Annotations
    • Nginx Location Directive
    • Nginx User
    • Nginx Port
    • Nginx Auth_request
    • Nginx Autoindex
    • Nginx if else
    • Nginx uWSGI
    • Nginx X-Forwarded-For
    • Nginx GUI
    • NGINX Unit
    • NGINX if
    • Nginx default_server
    • Nginx worker_connections
    • Nginx Authentication
    • Nginx Gateway Timeout
    • Nginx Error_page
    • Nginx Server Block
    • Nginx Forbidden
    • Nginx Modules
    • Nginx Max Upload Size
    • Nginx vs LiteSpeed
    • Nginx multiple server_name

Nginx Gateway Timeout

Introduction to Nginx Gateway Timeout

Nginx gateway timeout occurs during transactions, or our system might contain low resources; we can increase the system resources to resolve this issue in the future. It is widespread to see the nginx gateway timeout error using an nginx web server. This timeout error is generated for several reasons from the context of the back-end connection for the serving content.

Nginx Gateway Timeout

Overview of Nginx Gateway Timeout

We need to see which configuration we are using to fix the 504 gateway timeout of nginx. It is the 504 error that occurred while requesting a transaction to the nginx server. It means nginx is waiting for a lengthy response, which will be timed out. There are multiple reasons for this to occur. This problem can affect the nginx server. First, users will get a 504 nginx gateway timeout when we are using nginx as a reverse proxy, and it will time out while waiting for the server’s response and send a gateway timeout error.

How to Fix Error 504 Nginx Gateway Timeout?

Below are some of the critical ways to fix the error of 504 nginx gateway timeout as follows:

1. Server Goes Down

One of the most important causes of this issue is that our back-end server goes down because it will be overloaded with many requests or contain long-running requests. This issue will fix automatically when the server is started, and it got balanced for analyzing the server logs to identify the url which was requested just before our server shut down. However, sometimes it will contain the signal that we need to upgrade our server. The below example shows to check the status of the nginx server. If it stops, we can start by using the following command.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Code:

service nginx status
service nginx start

Output:

status of the nginx server

2. DNS Issue

This issue is from the client as well as the server side. If suppose we have found server-side DNS problems, this may be because the domain’s name is not resolving an IP in case we have changed the IP address of the migrated website to the new IP. Sometimes, it will take 5 minutes to 24 hours to update the DNS records. On the other hand, if suppose we have found client-side problems, then we can flush the DNS cache, which was local. DNS issue is a prevalent issue of nginx gateway timeout, and it will occur client as well as server side. The below example shows flush the DNS cache of the client-side as follows.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,560 ratings)

Code:

ipconfig /flushes

Output:

flush the DNS cache of the client-side

3. Disable CDN

If suppose our website is using the CDN, it will cause the timeout for returning the error of 504 gateway timeout. So, to solve this issue, we need to disable the CDN and try accessing the website.

4. Network Connectivity

Nginx will also give 504 errors if there are network connectivity issues between our end web server and the reverse proxy server. We need to log in to our proxy server and try connecting to the web server using the ping command. The below example shows to solve the issue of network connectivity between the end server and the reverse proxy server.

solve the issue of network connectivity

5. Firewall Issues

The nginx gateway timeout error occurs because the firewall is not configured correctly or it is not allowing any external traffic. It also blocks many requests, causing the nginx gateway timeout error. We can disable the firewall or need to configure the proper rule. In the below example, we are disabling the firewall as follows.

Code:

service ufw status

Output:

disabling the firewall

6. Faulty Plugins and Bugs

Faulty plugins and bugs also slow down our application, showing the gateway timeout error; in this case, we need to analyze the server logs to find which URL is causing this issue.

gateway timeout error

7. Spam, Bots, and DDOS Attack

Sometimes the malicious attack will break or flood our web server by using too many requests or running a slow request. At the same time, we need to monitor our log to see any spike in traffic; then, we need to identify the ranges and IP addresses for putting the measures in place to regulate the incoming request.

Spam, Bots and DDOS Attack

Increase Request in Nginx Gateway Timeout

By default, the nginx timeout is 60 seconds. However, we can increase the timeout to long-running server requests. If we don’t increase the timeout value, the nginx server will give the 504 error.

The below steps show how to increase the nginx gateway timeout request.

1. In this step, we install the nginx server on the ubuntu system. We are installing the nginx server by using the apt-get command.

Code:

apt-get install nginx

Output:

installing the nginx server by using the apt-get command

2. After installing the nginx server, we check the nginx installed version by using the following command. We can check the nginx version and the running status of the nginx server.

Code:

nginx –V

Output:

check the nginx installed version

3. After installing the nginx server in this step, we open the configuration file of nginx. We are opening the nginx configuration file using the vi command.

nginx configuration file using the vi command

4. After opening the nginx file now, we are increasing the timeout of the nginx gateway as follows. We are expanding the timeout from default to 500. We can also increase the nginx timeout for the specified folder.

Code:

http {
  proxy_read_timeout 300;
  proxy_connect_timeout 300;
  proxy_send_timeout 300;
}

Output:

xpanding the timeout from default to 500

5. After adding the connection timeout parameter in this step, we check the syntax and restart the nginx server.

Code:

nginx –t
service nginx restart

Output:

check the syntax and restart the nginx server

Conclusion

This timeout error is generated for several reasons from the context of the back-end connection for the serving content. First, it is the 504 error that occurred while requesting a transaction to the nginx server. We can increase system resources to resolve this issue that occurs in the future.

Recommended Articles

This is a guide to Nginx Gateway Timeout. Here we discuss the introduction and how to fix error 504 nginx gateway timeout with increased requests. You may also have a look at the following articles to learn more –

  1. Nginx Add_header
  2. Nginx Location Directive
  3. Nginx WAF
  4. Nginx FastCGI
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more