# Upstream "Sticky Connections?"

**URL:** <https://www.ruby-forum.com/t/upstream-sticky-connections/221528>\
**Category:** NGINX\
**Created:** [July 18, 2012, 3:52pm UTC](https://www.ruby-forum.com/t/upstream-sticky-connections/221528 "2012-07-18T15:52:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 18, 2012, 3:52pm UTC](https://www.ruby-forum.com/t/upstream-sticky-connections/221528/1 "2012-07-18T15:52:16Z")

</div>

Hello Everyone,

We are currently using Nginx 1.2.1 to terminate SSL and to load balance  
between two JBoss servers.

Here is my upstream block:

upstream jboss\_servers {  
ip\_hash;  
server 192.168.1.100:8080;  
server 192.168.1.101:8080;  
}

The issue we’re having is such – When a user is connected to Nginx,  
Nginx will proxy the connection to one of the two backend servers, for  
example 192.168.1.100. If we take that server offline (by stopping  
JBoss) the user is directed to the 192.168.1.101 server and their  
session is broken, requiring them to login again. We understand and  
accept this.

However, when server 192.168.1.100 is brought back online, Nginx is then  
redirecting their session back to that server, breaking their session  
and requiring them to login yet again.

Is there a directive I can use to prevent this behavior? I’ve seen this  
referred to in other places as sticky sessions, does Nginx support a  
similar method?

Posted at Nginx Forum:

> **[Upstream "Sticky Connections?"](https://forum.nginx.org/read.php?2,228685,228685#msg-228685)**
>
> Hello Everyone, We are currently using Nginx 1.2.1 to terminate SSL and to load balance between two JBoss servers. Here is my upstream block: upstream jboss\_servers { ip\_hash; server 192.168.1.100:8080; server 192.168.1.101:80

---

<div class="post-metadata">

**Author:** ![mevans336](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@mevans336](https://www.ruby-forum.com/u/mevans336)\
**Post date:** [July 18, 2012, 4:02pm UTC](https://www.ruby-forum.com/t/upstream-sticky-connections/221528/2 "2012-07-18T16:02:13Z")

</div>

2012/7/18 mevans336 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> ip\_hash;
> 
> However, when server 192.168.1.100 is brought back online, Nginx is then  
> redirecting their session back to that server, breaking their session  
> and requiring them to login yet again.
> 
> Is there a directive I can use to prevent this behavior? I’ve seen this  
> referred to in other places as sticky sessions, does Nginx support a  
> similar method?

you can look at this module:

> **[Google Code Archive - Long-term storage for Google Code Project Hosting.](https://code.google.com/archive/p/nginx-sticky-module)**

---

<div class="post-metadata">

**Author:** ![mevans336](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@mevans336](https://www.ruby-forum.com/u/mevans336)\
**Post date:** [July 18, 2012, 4:15pm UTC](https://www.ruby-forum.com/t/upstream-sticky-connections/221528/3 "2012-07-18T16:15:41Z")

</div>

Thank you Jérôme.

Our previous load balancers (Kemp Loadmasters) used the cookie method  
and it worked out well. We don’t currently build Nginx from source  
however, but rather we use the Ubuntu apt packages, so it would require  
a little work on our side to change this.

If anyone has suggestions that are native to Nginx, I would like to hear  
those as well.

Cheers,

Matt

Posted at Nginx Forum:

> **[Re: Upstream "Sticky Connections?"](https://forum.nginx.org/read.php?2,228685,228687#msg-228687)**
>
> Hello Everyone, We are currently using Nginx 1.2.1 to terminate SSL and to load balance between two JBoss servers. Here is my upstream block: upstream jboss\_servers { ip\_hash; server 192.168.1.100:8080; server 192.168.1.101:80
