# Upstream+ip\_hash: hash valid global?

**URL:** <https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697>\
**Category:** NGINX\
**Created:** [September 26, 2013, 12:43pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697 "2013-09-26T12:43:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [September 26, 2013, 12:43pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697/1 "2013-09-26T12:43:08Z")

</div>

Hello,

i have 2 upstreams, each with 3 backend servers, where backendA is the  
same  
backend in both upstreams.

upstream one {  
server backendA;  
server backendB;  
server backendC;  
}

upstream two {  
server backendA;  
server backendD;  
server backendE;  
}

A user with his IP sends a request, gets passed to upstream one and is  
sent  
to backendA. Shortly after that he sends a different request and gets  
passed  
to upstream two - will he be sent to backendA as well?

So the question is: is ip\_hash global in nginx, i.e. a user always is  
sent  
to the same backend (if available), independent from an upstream? Or is  
ip\_hash upstream-specific, i.e. nginx hashes per upstream?

thx in advance  
revirii

Posted at Nginx Forum:

> **[upstream+ip\_hash: hash valid global?](https://forum.nginx.org/read.php?2,243162,243162#msg-243162)**
>
> Hello, i have 2 upstreams, each with 3 backend servers, where backendA is the same backend in both upstreams. upstream one { server backendA; server backendB; server backendC; } upstream two { server back

---

<div class="post-metadata">

**Author:** ![revirii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@revirii](https://www.ruby-forum.com/u/revirii)\
**Post date:** [September 30, 2013, 2:12pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697/2 "2013-09-30T14:12:15Z")

</div>

hmm… no one? Is this unknown or a secret? At least i wasn’t able to  
find  
any detailed documentation about this.

Posted at Nginx Forum:

> **[Re: upstream+ip\_hash: hash valid global?](https://forum.nginx.org/read.php?2,243162,243259#msg-243259)**
>
> Hello, i have 2 upstreams, each with 3 backend servers, where backendA is the same backend in both upstreams. upstream one { server backendA; server backendB; server backendC; } upstream two { server back

---

<div class="post-metadata">

**Author:** ![revirii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@revirii](https://www.ruby-forum.com/u/revirii)\
**Post date:** [September 30, 2013, 2:32pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697/3 "2013-09-30T14:32:44Z")

</div>

Hello!

On Mon, Sep 30, 2013 at 08:11:13AM -0400, revirii wrote:

> hmm… no one? Is this unknown or a secret? At least i wasn’t able to find  
> any detailed documentation about this.

It’s an implementation detail. As of now, two identical  
upstream{} blocks will map the same ip address to the same peer’s  
number. But it’s not something guaranteed.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)

---

<div class="post-metadata">

**Author:** ![revirii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@revirii](https://www.ruby-forum.com/u/revirii)\
**Post date:** [September 30, 2013, 3:16pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697/4 "2013-09-30T15:16:32Z")

</div>

Hi,

thanks for your answer 🙂

> It’s an implementation detail. As of now, two identical  
> upstream{} blocks will map the same ip address to the same peer’s  
> number. But it’s not something guaranteed.

ok, this is the behaviour when the upstreams are identical, i.e. they  
have  
the same backends. That would be ok for me.

But what if the backends are not identical? My example was:

upstream one {  
server backendA;  
server backendB;  
server backendC;  
}

upstream two {  
server backendA;  
server backendD;  
server backendE;  
}

If a user sends a request - \> upstream:one → backendA and then makes a  
request where upstream:two is used, is he then sent to backendA as well?  
Ok,  
this would be nice to know, but it’s not that important 😉

revirii

Posted at Nginx Forum:

> **[Re: upstream+ip\_hash: hash valid global?](https://forum.nginx.org/read.php?2,243162,243262#msg-243262)**
>
> Hello, i have 2 upstreams, each with 3 backend servers, where backendA is the same backend in both upstreams. upstream one { server backendA; server backendB; server backendC; } upstream two { server back

---

<div class="post-metadata">

**Author:** ![revirii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@revirii](https://www.ruby-forum.com/u/revirii)\
**Post date:** [September 30, 2013, 5:07pm UTC](https://www.ruby-forum.com/t/upstream-ip-hash-hash-valid-global/236697/5 "2013-09-30T17:07:01Z")

</div>

Hello!

On Mon, Sep 30, 2013 at 09:16:14AM -0400, revirii wrote:

> server backendD;  
> server backendE;  
> }
> 
> If a user sends a request - \> upstream:one → backendA and then makes a  
> request where upstream:two is used, is he then sent to backendA as well? Ok,  
> this would be nice to know, but it’s not that important 😉

As long as all servers configured map to the same number of  
peers (in most simple case - each “backendX” resolves to a single  
ip address) - such backends are identical for the above sentence,  
and the request will be sent to “backendA” in both cases.

But, again, this isn’t something guaranteed.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)
