# Conditional balancing

**URL:** <https://www.ruby-forum.com/t/conditional-balancing/245962>\
**Category:** NGINX\
**Created:** [August 4, 2013, 10:43pm UTC](https://www.ruby-forum.com/t/conditional-balancing/245962 "2013-08-04T22:43:57Z")\
**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:** [August 4, 2013, 10:43pm UTC](https://www.ruby-forum.com/t/conditional-balancing/245962/1 "2013-08-04T22:43:57Z")

</div>

I am developing a webmail service where the user’s inbox and all  
related session variables will be loaded to one of many application  
servers which will be behind the balancer (running nginx). So, I need  
nginx to direct all requests of a particular user, to a particular  
application server. How can it be done?  
One way, I think, is to integrate zookeeper into nginx as module, this  
way nginx will communicate with the application daemon and always know  
which appserver is holding user’s session and data. But this is a lot  
of work, is there any other solution to do this sort of conditional  
balancing ?

Thanks in advance  
Nulik

---

<div class="post-metadata">

**Author:** ![Nulik\_Nol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecccb3/32.png) [@Nulik\_Nol](https://www.ruby-forum.com/u/Nulik_Nol)\
**Post date:** [August 4, 2013, 11:48pm UTC](https://www.ruby-forum.com/t/conditional-balancing/245962/2 "2013-08-04T23:48:13Z")

</div>

Hello!

On Sun, Aug 04, 2013 at 03:43:16PM -0500, Nulik Nol wrote:

> I am developing a webmail service where the user’s inbox and all  
> related session variables will be loaded to one of many application  
> servers which will be behind the balancer (running nginx). So, I need  
> nginx to direct all requests of a particular user, to a particular  
> application server. How can it be done?  
> One way, I think, is to integrate zookeeper into nginx as module, this  
> way nginx will communicate with the application daemon and always know  
> which appserver is holding user’s session and data. But this is a lot  
> of work, is there any other solution to do this sort of conditional  
> balancing ?

Trivial solution would be to use a cookie to specify backend  
needed, and set the cookie during login.

–  
Maxim D.

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

---

<div class="post-metadata">

**Author:** ![Nulik\_Nol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecccb3/32.png) [@Nulik\_Nol](https://www.ruby-forum.com/u/Nulik_Nol)\
**Post date:** [August 6, 2013, 9:23am UTC](https://www.ruby-forum.com/t/conditional-balancing/245962/3 "2013-08-06T09:23:01Z")

</div>

essence of the other tow ansers:

[http://dgtool.blogspot.de/2013/02/nginx-as-sticky-balancer-for-ha-using.html](http://dgtool.blogspot.de/2013/02/nginx-as-sticky-balancer-for-ha-using.html)

you might want to google “nginx sticky sessions”

Posted at Nginx Forum:

> **[Re: Conditional balancing](https://forum.nginx.org/read.php?2,241556,241627#msg-241627)**
>
> I am developing a webmail service where the user's inbox and all related session variables will be loaded to one of many application servers which will be behind the balancer (running nginx). So, I need nginx to direct all requests of a particular...

---

<div class="post-metadata">

**Author:** ![Nulik\_Nol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecccb3/32.png) [@Nulik\_Nol](https://www.ruby-forum.com/u/Nulik_Nol)\
**Post date:** [August 5, 2013, 7:05am UTC](https://www.ruby-forum.com/t/conditional-balancing/245962/4 "2013-08-05T07:05:20Z")

</div>

Serverside cookies for session management tho itl be more of a static  
Pre-determined mapping… Aka  
Stickysessions

–  
Payam C.  
Network Engineer / Security Specialist
