fix nginx upstream timed out error

How to Fix NGINX Upstream Timed Out Error

Sometimes you may get an “Upstream Timed Out” error in NGINX server, when it is used as reverse proxy. This happens mainly because your upstream server takes too much times to respond to the request. So NGINX thinks the upstream server has failed to process the request and returns an error message. In this article, we will look at how to fix this problem.


How to Fix NGINX Upstream Timed Out Error

Here are the steps to fix Upstream Timed out error in NGINX.


1. Open NGINX configuration file

Open terminal and run the following command to open NGINX configuration file.

$ sudo vi /etc/nginx/nginx.conf


2. Add proxy_read_timeout

proxy_read_timeout directive allows you to increase the timeout value for requests sent to upstream servers in NGINX. Here is its syntax.

proxy_read_timeout timeout

You need to specify the timeout value in seconds, after proxy_read_timeout

Add the following directive to the URL location which times out, to increase request timeout to 3600 seconds, that is, 1 hour.

proxy_read_timeout 3600

Let us say you get upstream timed out error in /product URL, then add the above directive to its location block.

location /product {
   ...
   proxy_read_timeout 3600;
   ...
}

If you get this error for all URLs, or if you want to increase request timeout for all URLs, then add it to the server block.

server {
   ...
   proxy_read_timeout 3600;

   location / {
      ...
   }
   ...
}


3. Restart NGINX Server

Test NGINX configuration for errors with the following command.

$ sudo nginx -t

If you don’t get any error messages, restart NGINX server to apply changes.

$ sudo service nginx restart 

Also read:

How to Fix Upstream Sent Too Big Header Error in NGINX
How to Install more_set_headers in NGINX
How to Fix Permission Denied Error in Django
How to Modify Response Header in NGINX
How to Get Data from URL in NodeJS

Leave a Reply

Your email address will not be published. Required fields are marked *