Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Currently, we are using apache2 as frontend, and tomcat as backend. We are using mod_proxy_balancer and AJP. Also we are using stickysession by JSESSIONID cookie:

<Proxy balancer://backend>
     BalancerMember ajp://127.0.0.1:8008 min=10 max=100 ping=5 connectiontimeout=40 ttl=60   retry=20 route=node-1
     BalancerMember ajp://127.0.0.1:8009 min=10 max=100 ping=5 connectiontimeout=40 ttl=60 retry=20 route=node-2
     ProxySet lbmethod=byrequests timeout=30
     ProxySet stickysession=JSESSIONID|jsessionid nofailover=Off
</Proxy>

and using jvmRoute parameter in web.xml to add tail to JSESSIONID cookie:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="node-1">

We are looking to switch to using nginx for our frontend. So far I haven't found any way to perform the same session affinity operation with nginx. Is there any solution for this? We are not using session replication, so getting sequential requests to the same backend is crucial.

share|improve this question
    
So your actual question is "how can I do sticky sessions by cookie with nginx?"? –  womble Jul 6 '12 at 9:08
    
Yes, in short my question is "how to do sticky session by cookie with nginx". Sorry, if my question is too vague in first place. –  Slezhuk Jul 6 '12 at 9:43
1  
Question edited to reflect this. It's best if you do this yourself in future. –  womble Jul 6 '12 at 9:57
1  
If I may ask, what is your reason for going to nginx? Are you just looking to maintain connection to one server? This is not an answer to your question, but look at a load balancer like HAProxy as an alternative: serverfault.com/questions/381856/… Good luck! –  KM. Jul 6 '12 at 13:14
1  
Ah static content, you didn't mention that before (_; HAProxy might be able to, but I'm unsure. I saw a few posts about it. Not to add to your list of things to look at, but have a look at Varnish -- it might be the solution that needs (all?) your stated needs (-; Or tune/trouble-shoot your instance of Apache. –  KM. Jul 6 '12 at 17:31

1 Answer 1

up vote 4 down vote accepted

Google suggests that there is an out-of-tree module for nginx that does this. I've never used it, since I consider sticky sessions to be the work of satan, but it'll be the first option I'd use if I had to implement it.

share|improve this answer
    
I saw this module. But i affraid of using 3rd party module, which was last updated in Sep 2009. And what solution do you recommend, if not using sticky session? –  Slezhuk Jul 6 '12 at 10:19
3  
Use a proper shared session store. I've looked at JBoss session replication, and it terrifies me, so I'm guessing that Tomcat's is probably just as scary, so I'd look towards something like github.com/xetorthio/redis-store (because I have a hard-on for Redis). –  womble Jul 6 '12 at 10:23
    
Last time i talked to our programmers they said, that we cannot implement session replication now, because we have some unserrializeble objects in sessions. I'am not java programmer, so i don't know how hard it will be to make it serrializeble, or is it possible at all. So far i think we stuck with sticky sessions :( –  Slezhuk Jul 6 '12 at 10:34
4  
And this is why the Internet can't have nice things. Please do everyone a favour and beat your programmers with sticks. Keeping your session data serializable is Web Programming 101. –  womble Jul 6 '12 at 10:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.