# Cookie and first load balancing

**URL:** <https://www.ruby-forum.com/t/cookie-and-first-load-balancing/229332>\
**Category:** NGINX\
**Created:** [January 15, 2013, 12:26am UTC](https://www.ruby-forum.com/t/cookie-and-first-load-balancing/229332 "2013-01-15T00:26:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KT\_Walrus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a87d85/32.png) [@KT\_Walrus](https://www.ruby-forum.com/u/KT_Walrus)\
**Post date:** [January 15, 2013, 12:26am UTC](https://www.ruby-forum.com/t/cookie-and-first-load-balancing/229332/1 "2013-01-15T00:26:15Z")

</div>

The only reason I need haproxy in my software stack is for “cookie  
persistence” and “first” load balancing. I’d like to use nginx instead.

Can I do the equivalent of haproxy “cookie persistence” in nginx by  
testing if the request has a cookie set and then testing this cookie’s  
value to decide which upstream to use? Seems possible to me.

As for haproxy’s “first” load balancing, is there a variable in nginx  
that I can test for a given server which yields the current number of  
active connections that nginx has with that server? I haven’t found any  
such variable in nginx’s documentation.

Kevin
