# Proxy\_read\_timeout vs proxy\_next\_upstream\_timeout

**URL:** <https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374>\
**Category:** NGINX\
**Created:** [March 29, 2016, 5:04pm UTC](https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374 "2016-03-29T17:04:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [March 29, 2016, 5:04pm UTC](https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374/1 "2016-03-29T17:04:23Z")

</div>

Hi

If you set read timeout 2 min and next upstream timeout 50 seconds, will  
nginx break the current connection at 50 second or will it let the read  
finish until 2min?

Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [March 29, 2016, 7:13pm UTC](https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374/2 "2016-03-29T19:13:29Z")

</div>

Those directives works at very different levels.

proxy\_next\_upstream\_timeout  
[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_next\_upstream\_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_timeout)  
allocates a time for nginx to find a proper upstream (configured with  
proxy\_next\_upstream  
[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_next\_upstream](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream)  
).  
By default, there is no limit, making nginx attempting every upstream  
one  
after the other until finding one healthy or running out of valid  
upstreams, which could take a while (maybe even an infinite time with  
health checks? Speculating here).

proxy\_read\_timeout  
[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_read\_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout)  
sets a timer ‘between two read operations’, say the docs, which is  
closer  
to your question.  
Those are to be defined, but I suppose that when there is nothing more  
to  
read in the buffer awaiting backend response, and the response is not  
complete, this timer kicks in and effectively close the connection,  
returning an error.

## ​They are not working at the same level at all: there is no way to mistake one for the other.​

_B. R._

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [March 31, 2016, 6:55pm UTC](https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374/3 "2016-03-31T18:55:25Z")

</div>

Given this config:  
proxy\_next\_upstream timeout;  
proxy\_next\_upstream\_timeout 50;  
proxy\_connect\_timeout 10;  
proxy\_read\_timeout 100;  
If upstream has issues causing connect timeout, nginx will re-try 5  
upstream servers until hitting 50, then fail.  
If one upstream has issues causing read timeout, nginx will keep wait to  
read, until 100, then timeout, then checks the  
proxy\_next\_upstream\_timeout  
which is 50 and already passed, so nginx won’t retry next upstream.

I am trying to setup nginx to only retry on connect timeout, not read  
timeout, will above work?

---

<div class="post-metadata">

**Author:** ![fjlj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e79b87/32.png) [@fjlj](https://www.ruby-forum.com/u/fjlj)\
**Post date:** [April 1, 2016, 12:33am UTC](https://www.ruby-forum.com/t/proxy-read-timeout-vs-proxy-next-upstream-timeout/244374/4 "2016-04-01T00:33:39Z")

</div>

On Thu, Mar 31, 2016 at 6:54 PM, Frank L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Given this config:  
> proxy\_next\_upstream timeout;  
> proxy\_next\_upstream\_timeout 50;  
> proxy\_connect\_timeout 10;  
> proxy\_read\_timeout 100;  
> If upstream has issues causing connect timeout, nginx will re-try 5  
> upstream servers until hitting 50, then fail.

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_timeout)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

‘[…] hitting 50s […]’ (cf. [Configuration file measurement units](http://nginx.org/en/docs/syntax.html))​

> If one upstream has issues causing read timeout, nginx will keep wait to  
> read, until 100, then timeout,

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

​nginx will wait for a maximum of 100s between two successful read  
operations (or before the first one) and will fail if exceeded.  
​

> then checks the proxy\_next\_upstream\_timeout which is 50 and already  
> passed, so nginx won’t retry next upstream.
> 
> I am trying to setup nginx to only retry on connect timeout, not read  
> timeout, will above work?

## ​ [Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) The ‘timeout’ property regroups conneciton timeout and header read timeout​. Content read timeout is set by proxy\_read\_timeout [http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_read\_timeout](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) (default 60s)

_B. R._
