You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by michael bienstein <mb...@yahoo.fr> on 2010/08/26 11:57:29 UTC

[users@httpd] Sticky Session with no control on origin server cookies

Hi all. I'm trying to configure a proxy_loadbalancer with sticky session. I read 
around the web and in the source code and discovered that this module expects to 
handle sticky session by re-using the user's session ID provided by the origin 
server. This is different to BigIP which injects its own cookie that it keeps 
track of. Apache also expects the origin server to know it is being 
load-balanced and to change the session ID it creates to include a "route" that 
identifies that origin server.

So for example if my origin server is Tomcat then the session cookie would be 
JSESSIONID=12345... and Tomcat has to be modified to make it 
JSESSIONID="12345.route1". Apache mod_proxy_loadbalancer sees this and finds the 
route1 and chooses the right origin server based on that. I also read that PHP 
doesn't have the possibility of changing the cookie, but since PHP runs 
typically on Apache, it is possible to modify the configuration of the origin 
server to post-process the request to add it.

My problem is that I load balance a custom web server and/or IIS and we have 
neither of these options available. I need the cookie to go through as 
originally created and I can't change the way it gets created. So, how to do it?

I have tried to add a cookie at the proxy server, but I can't get this to only 
happen when the origin server sends through its cookie. In fact if the origin 
server sends an error code, the environment variable I use with SetEnvIf isn't 
set correctly. I can't see how to add a cookie in a post-processing filter of 
some sort either. The only ways I see to add cookies are in mod_rewrite (which 
seems strange to me) and via mod_headers.

Any ideas?

Thanks,

Michael


      

Re: [users@httpd] Sticky Session with no control on origin server cookies

Posted by Rainer Jung <ra...@kippdata.de>.
On 26.08.2010 11:57, michael bienstein wrote:
> Hi all. I'm trying to configure a proxy_loadbalancer with sticky
> session. I read around the web and in the source code and discovered
> that this module expects to handle sticky session by re-using the user's
> session ID provided by the origin server. This is different to BigIP
> which injects its own cookie that it keeps track of. Apache also expects
> the origin server to know it is being load-balanced and to change the
> session ID it creates to include a "route" that identifies that origin
> server.
>
> So for example if my origin server is Tomcat then the session cookie
> would be JSESSIONID=12345... and Tomcat has to be modified to make it
> JSESSIONID="12345.route1". Apache mod_proxy_loadbalancer sees this and
> finds the route1 and chooses the right origin server based on that. I
> also read that PHP doesn't have the possibility of changing the cookie,
> but since PHP runs typically on Apache, it is possible to modify the
> configuration of the origin server to post-process the request to add it.
>
> My problem is that I load balance a custom web server and/or IIS and we
> have neither of these options available. I need the cookie to go through
> as originally created and I can't change the way it gets created. So,
> how to do it?
>
> I have tried to add a cookie at the proxy server, but I can't get this
> to only happen when the origin server sends through its cookie. In fact
> if the origin server sends an error code, the environment variable I use
> with SetEnvIf isn't set correctly. I can't see how to add a cookie in a
> post-processing filter of some sort either. The only ways I see to add
> cookies are in mod_rewrite (which seems strange to me) and via mod_headers.
>
> Any ideas?

Have a look at the second example in

http://httpd.apache.org/docs/trunk/mod/mod_proxy_balancer.html#example

It uses the following features:

- Apache itself can also set a cookie
- the value of the cookie can be interpolated from
   Apache environment variables that are being set
   by the balancer
- setting the cookie can be made dependent on
   whether the load balancer set a variable indicating
   that the request changed nodes (or wasn't sticky)

All of the ingredients used in this example for Apache trunk (the actual 
beta version 2.3) should IMHO be already available in 2.2 (except for 
the nice example in the docs).

If you want to track how this works, you can add

%{Set-Cookie}o %{ROUTEID}C %{BALANCER_WORKER_ROUTE}e 
%{BALANCER_ROUTE_CHANGED}e

to your LogFormat (Access-Log).

NOTE: I think the first of these config lines should use "Set-Cookie" 
instead of "Set-Cookie:".

Regards,

Rainer

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org