Apache load balancing when the session id is in url

apache-2.2load balancingmod-jkmod-proxy

I really have no idea…

I have a java web application which stores the session id in URL rather than using cookies. I want to run the application on 2 tomcat servers and fronting them with an Apache server for load balancing.


            __ tomcat1
Apache ----/
           \__ tomcat2

By setting the jvmRoute to tomcat1in the Tomcat server.xml file, the url will become http://url;jsessionid=id.tomcat1. So it is possible to achieve session stickyness by looking at the url, and route it to the corresponding server.

I know that mod_proxy and mod_jk and do the load balancing, but their sticky session only work when the session id is stored in cookies. In my case, the session id is encoded in the URL. How can I do the load balancing?

Best Answer

Maybe your configuration is wrong. Documentation is not specified sticky-session working only cookies.

stickysession - Balancer sticky session name. The value is usually set to something like JSESSIONID or PHPSESSIONID, and it depends on the backend application server that support sessions. If the backend application server uses different name for cookies and url encoded id (like servlet containers) use | to to separate them. The first part is for the cookie the second for the path.

So you can specify the sessionid like below.

ProxyPass / balancer://mycluster/ stickysession=|jsessionid

Hope this helps.