I'm using apache httpd with ProxyPass and DNS RR and sticky Java sessions for Tomcat.

It's not working.

My apache config is:

ProxyPass "/" "balancer://mycluster/" stickysession=JSESSIONID|jsessionid scolonpathdelim=On

<Proxy balancer://mycluster>
    BalancerMember http://stest:8080/

<Location "/balancer-manager">
    SetHandler balancer-manager
    Require host localhost

When I do an nslookup stest on the httpd host I have 5 hosts that come back:

root@sproxy:/app# nslookup stest

Non-authoritative answer:
Name:   stest
Name:   stest
Name:   stest
Name:   stest
Name:   stest

Thus, my httpd server should route to one of these IP addresses until a JSESSIONID cookie is set and then it should be sticky for that IP.

The problem is, this does not work. When I do:

while true; do curl -b /tmp/cj.txt -c /tmp/cj.txt -w '\n' localhost/test-session-servlet/json ; done

I get my servlet output, which includes the Tomcat host that I hit and the session id.

I would expect this to only hit one server, since the cookie gets set in /tmp/cj.txt and is passed to every request. I get the same output with the above command as I do with:

while true; do curl -w '\n' localhost/test-session-servlet/json ; done

(note the above command does not use cookies, so it should be load balanced even with sticky sessions because it does not pass the cookie)

In essence, both curl commands send to different servers as if the sticky sessions are not enabled properly, but the first should not do this.

What am I doing wrong here?


Tomcat and httpd are working as designed. The problem is the architecture you have set up is never going to work. You need the route in httpd.conf and the jvmRoute in server.xml to be set and consistent.

One possible solution is to explicitly define each of the stest hosts in your httpd.conf file. Something like:

<Proxy balancer://mycluster>
  BalancerMember route=tc01
  BalancerMember route=tc02
  BalancerMember route=tc03
  BalancerMember route=tc04
  BalancerMember route=tc05

You'll also need to set the jvmRoute on the <Engine> element in the server.xml of each Tomcat instance and ensure that it is consistent with the route defined above.

  • So how do I use RR DNS with an httpd reverse proxy & sticky sessions? – mikeb Feb 3 '18 at 19:36
  • You can't. Logically it can't work. If there is only a single host defined, httpd has no way to route the request to the correct host. – Mark Thomas Feb 3 '18 at 19:38
  • There's a single host name defined, it resolves to multiple IP addresses. – mikeb Feb 7 '18 at 19:57
  • Think about it. If httpd routes by host name, how can it control which of the multiple IP addresses it routes a request to? It can't. It has to route by IP address which means the BalancerMembers need to be defined by IP address not host name. – Mark Thomas Feb 7 '18 at 20:00
  • I understand that, but when using RR DNS your hostname resolves to multiple IP addresses - so it would be possible to support it... – mikeb Feb 8 '18 at 18:21

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.