I am using apache web server as a load balancer for two tomcat instances behind apache. When the first request goes to node A and second request from the same client goes to node B, i cant access session variables within node A. It's obvious. I surfed in the internet and found that enabling sticky sessions would help. But all the tutorials for enabling the sticky sessions in apache look confusing. Is there any simple step-by-step tutorial for this? Please help.
Code fragment from comment:
ProxyPass /balancer-manager !
ProxyPass /balancer://mycluster/ stickysession=JSESSIONID
ProxyPassReverse /balancer://mycluster/
<Proxy balancer://mycluster>;
BalancerMember ajp://localhost:9001/ route=NodeA1000 retry=10
BalancerMember ajp://localhost:9002/ route=NodeB1000 retry=10
</Proxy>
Yes. Apache HTTPd can delegate to Apache Tomcat using ModProxy or ModAJP, and can be configured to do so based on the domain, path or file extension requested. Your Apache HTTPd configuration of PHP would remain the same.
Tomcat provides in-memory session replication through a combination of serializable session attributes, "sticky sessions", which are provided by the load balancer, and specialized components configured in Tomcat's XML configuration files.
Application Load Balancers support both duration-based cookies and application-based cookies. Sticky sessions are enabled at the target group level. You can use a combination of duration-based stickiness, application-based stickiness, and no stickiness across your target groups.
This worked for me...
Instead of using stickysession=JSESSIONID in ProxyPass directive it has to be set within balancer configuration using ProxySet stickysession=JSESSIONID:
<Proxy balancer://mybalancer>
BalancerMember ajp://server1:8009 route=tomcat1
BalancerMember ajp://server2:8009 route=tomcat2
ProxySet lbmethod=bytraffic
ProxySet stickysession=JSESSIONID
</Proxy>
ProxyPass /myapp/ mybalancer://myapp/
It was not working for me when I was using it in ProxyPass as shown below:
ProxyPass /myapp/ mybalancer://myapp/ stickysession=JSESSIONID
For apache httpd to keep your sessions tied to the same backend, it needs to know which cookie keeps the session ID. For java, this is (usually) JSESSIONID.
If you're using the ProxyPass
directive, use
ProxyPass /example http://backend.example.com stickysession=JSESSIONID
To be found in the excellent apache httpd documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With