2

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.

womble
  • 95,029
  • 29
  • 173
  • 228
Slezhuk
  • 365
  • 2
  • 6
  • So your actual question is "how can I do sticky sessions by cookie with nginx?"? – womble Jul 06 '12 at 09: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 06 '12 at 09:43
  • 1
    Question edited to reflect this. It's best if you do this yourself in future. – womble Jul 06 '12 at 09: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: http://serverfault.com/questions/381856/haproxy-and-persistant-connections Good luck! – KM. Jul 06 '12 at 13:14
  • There is no special reason to go to nginx for now. For now it is just a hypothesis, that with nginx as frontend site will run faster and more reliable. I will look at HAProxy, thanx. But i still wanted to serve static content from frontend server, and i think HAProxy do not serve content, only proxying. Am i wrong? – Slezhuk Jul 06 '12 at 14:16
  • 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 06 '12 at 17:31

1 Answers1

4

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.

womble
  • 95,029
  • 29
  • 173
  • 228
  • 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 06 '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 https://github.com/xetorthio/redis-store (because I have a hard-on for Redis). – womble Jul 06 '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 06 '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 06 '12 at 10:36