# Upstream keepalive with upstream hash

**URL:** <https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456>\
**Category:** NGINX\
**Created:** [March 15, 2013, 8:49pm UTC](https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456 "2013-03-15T20:49:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![beaufour](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@beaufour](https://www.ruby-forum.com/u/beaufour)\
**Post date:** [March 15, 2013, 8:49pm UTC](https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456/1 "2013-03-15T20:49:28Z")

</div>

I’ve been trying to get this setup working:  
client ← c0 → nginx1 ← c1 → nginx2 ← c2 → service (http)

where the c1 connection is kept alive between request from from the  
outside,  
but c0 and c2 are closed after each request. I’ve used the ‘keepalive’  
keyword in the upstream nginx1 config, and it works. Unfortunately I  
also  
use the upstream hash patch on nginx1, and as soon as I enable that  
nginx1  
closes the connection forcefully. I’ve confirmed this with tcpdump in  
both  
setups, and it’s the only difference. Any hints to what I can do?

I’m suspecting that the upstream hash module “takes over” the upstream  
handling, and thus ignores the ‘keepalive’ keyword, but I’m randomly  
guessing.

Thanks,

Allan

Posted at Nginx Forum:

> **[upstream keepalive with upstream hash](https://forum.nginx.org/read.php?2,237417,237417#msg-237417)**
>
> I've been trying to get this setup working: client \<- c0 -\> nginx1 \<- c1 -\> nginx2 \<- c2 -\> service (http) where the c1 connection is kept alive between request from from the outside, but c0 and c2 are closed after each request....

---

<div class="post-metadata">

**Author:** ![beaufour](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@beaufour](https://www.ruby-forum.com/u/beaufour)\
**Post date:** [March 15, 2013, 9:11pm UTC](https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456/2 "2013-03-15T21:11:06Z")

</div>

I also just tried the ip\_hash module and it also disables the keepalive  
functionality ☹

Posted at Nginx Forum:

> **[Re: upstream keepalive with upstream hash](https://forum.nginx.org/read.php?2,237417,237420#msg-237420)**
>
> I've been trying to get this setup working: client \<- c0 -\> nginx1 \<- c1 -\> nginx2 \<- c2 -\> service (http) where the c1 connection is kept alive between request from from the outside, but c0 and c2 are closed after each request....

---

<div class="post-metadata">

**Author:** ![beaufour](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@beaufour](https://www.ruby-forum.com/u/beaufour)\
**Post date:** [March 17, 2013, 12:14am UTC](https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456/3 "2013-03-17T00:14:07Z")

</div>

Hello!

On Fri, Mar 15, 2013 at 03:48:56PM -0400, beaufour wrote:

> I’m suspecting that the upstream hash module “takes over” the upstream  
> handling, and thus ignores the ‘keepalive’ keyword, but I’m randomly  
> guessing.

Quoting [Alphabetical index of directives](http://nginx.org/r/keepalive:)

: When using load balancer methods other than the default  
: round-robin, it is necessary to activate them before the keepalive  
: directive.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![beaufour](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@beaufour](https://www.ruby-forum.com/u/beaufour)\
**Post date:** [March 18, 2013, 2:53pm UTC](https://www.ruby-forum.com/t/upstream-keepalive-with-upstream-hash/227456/4 "2013-03-18T14:53:35Z")

</div>

Maxim D. Wrote:

> > I’m suspecting that the upstream hash module “takes over” the  
> > upstream  
> > handling, and thus ignores the ‘keepalive’ keyword, but I’m randomly  
> > guessing.
> 
> Quoting [Alphabetical index of directives](http://nginx.org/r/keepalive:)
> 
> : When using load balancer methods other than the default  
> : round-robin, it is necessary to activate them before the keepalive  
> : directive.

Doh! That seems to do the trick. Thanks!

Allan

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,237417,237489#msg-237489](http://forum.nginx.org/read.php?2,237417,237489#msg-237489)
