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:// min=10 max=100 ping=5 connectiontimeout=40 ttl=60   retry=20 route=node-1
     BalancerMember ajp:// 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

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.

  • 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

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.

  • 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
  • 5
    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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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