Apache / Define stickiness with JSESSIONID

2.1k views Asked by At

I try to define stickiness in Apache. Here is the definition in proxy.conf:

<Proxy balancer://fs1>
    BalancerMember https://localhost:5006/doc route=node1
    BalancerMember https://localhost:5008/doc route=node2
    ProxySet stickysession=JSESSIONID|jsessionid
</Proxy>
ProxyPass /doc balancer://fs1

or:

ProxyPass "/doc " "balancer://fs1" stickysession=JSESSIONID|jsessionid scolonpathdelim=On
<Proxy balancer://fs1>
    BalancerMember https://localhost:5006/doc route=node1
    BalancerMember https://localhost:5008/doc route=node2
</Proxy>

I try to use the url query param in order to achieve stickiness (because I understand that is not recommended to override cookie). As written in the Apache documentation:

The second way of implementing stickyness is URL encoding. The web server searches for a query parameter in the URL of the request. The name of the parameter is specified again using stickysession. The value of the parameter is used to lookup a member worker with route equal to that value. Since it is not easy to extract and manipulate all URL links contained in responses, generally the work of adding the parameters to each link is done by the back-end generating the content. In some cases it might be feasible doing this via the web server using mod_substitute or mod_sed. This can have negative impact on performance though.

I send the following request 10 times in postman:

https://{{myserver}}/doc?jsessionid=node1

I notice that the requests are passed to node1 (5 requests) and to node2 (also 5 requests). But I define the stickysession so it should choose node1, and go to this node every time.

My goal is that the client will send the request https://{{myserver}}/doc?jsessionid=nodeX, and the request will pass to nodeX (without using cookie.., only using stickyness is URL encoding).

For example, the client sends the request https://{{myserver}}/doc?jsessionid=node1 10 times. Every 10 times the request will be served by https://localhost:5006.

What I do wrong?

1

There are 1 answers

0
Jacob Margason On BEST ANSWER

After some searching, I have identified the problem. In order to route via URL request parameters you must include a '.' before the 'node1' like so:

https://{{myserver}}/doc?jsessionid=.node1

This blog post pointed me in the right direction:

It is very important that the routes are named by an alphanumeric prefix, a dot and then a number. Eg: server.1, t.2 etc. The mod_proxy_balancer code splits this route name using the dot and uses the second value as the route number. So s.1 would point to “route=1" http://hkrishnan.in/2013/10/14/debugging-apache-mod_proxy_balancer/

I have tested this myself and it works great!