Here is my problem: I have 3 Tomcat 7.0.x servers, and 2 Apache 2.2.x HTTPd servers, see the image. (All servers are running Linux Redhat 6.2.)
So I have load balancing setup between Tomcat 1/2, and house some small Micro-service on Tomcat 3, and not load balanced. At the Apaches I'm using round robin with sticky sessions, and mod_proxy_ajp to the Tomcat nodes.
<Virtual *:80>
Header Add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://t-ha-cluster>
ProxySet lbmethod=byrequest
BalancerMember ajp://tomcat1:8109 route=jvm-tc-1 connectiontimeout=400ms retry=60 ping=5
BalancerMember ajp://tomcat2:8109 route=jvm-tc-2 connectiontimeout=400ms retry=60 ping=5
ProxySet stickysession=ROUTEID
</Proxy>
<Proxy balancer://t-micro-cluster>
ProxySet lbmethod=byrequest
BalancerMember ajp://tomcat3:8109 route=jvm-tc-3 connectiontimeout=400ms retry=60 ping=5
ProxySet stickysession=ROUTEID
</Proxy>
<Location /app1>
ProxyPass balancer://t-ha-cluster/myapp stickysession=ROUTEID
ProxyPassReverse stickysession=ROUTEID
</Location>
<Location /app2>
ProxyPass balancer://t-ha-cluster/myapp stickysession=ROUTEID
ProxyPassReverse stickysession=ROUTEID
</Location>
<Location /search>
ProxyPass balancer://t-micro-cluster/myapp stickysession=ROUTEID
ProxyPassReverse stickysession=ROUTEID
</Location>
</Virtual>
Now when I go to /app1 a ROUTEID=.jvm-tc-2 is created, and session is created on Tomcat 2 server. On the page load it fetches small search widget from /search on Tomcat 3, which changes my ROUTEID=.jvm-tc-3. Then the next request fetches resources from /app, I get ROUTEID=.jvm-tc-1. So now a new session is created on Tomcat 1 node. Is there a better way of writing my Apache configuration, so that the user stays on Tomcat 2 the entire time? And is there a way to make it reusable for other applications as we expand our app stack?
I would rather not keep ROUTEIDs per /appx context, since that would start to be maintenance nightmare.