You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Andrea <pa...@eng.it> on 2005/05/25 18:53:21 UTC

[users@httpd] help needed on Load balancing and environment variables scope

Hy everybody,
I'm configuring Apache as a reverse proxy and I am doing loadbalancing between some backend servers.
I' am doing load balancing using mod_rewrite. My backend webapps (every webapp is replicated in various servers) use cookies to mantain sessions.

So my goal was to redirect every user to same server he first was redirected to.
I achieved this setting the environment variable SERVER to the server name the user is first redirected to, then storing this value in a cookie; all the following request of the same user are then redirected to the server whose name is stored in the "backend_server" cookie.

 My question is: 
what is the scope of the SERVER environment variable ? What happens if many users request simultaneusly ? Does the value of SERVER is shared inconsistently ? 
I mean...may a user be redirected to the wrong server ?

Below I enclose the my config.

Any help is really appreciated.
Thanks
Andrea


RewriteMap lb rnd:/usr/local/apache2/conf/backend.table
RewriteCond %{HTTP_COOKIE} (^|(.+;)*)backend_server=(.+)(;?)
RewriteRule ^/s1_webconsole/(.*)$  http://%3/webconsole/$1 [E=SERVER:%3,P,L] 
RewriteCond %{HTTP_COOKIE} !(^|(.+;)*)backend_server=(.+)(;?)
RewriteRule ^/s1_webconsole/(.*)$  to://${lb:www}/$1
RewriteRule ^to://([^/]+)/(.*)$  http://$1/$2 [E=SERVER:$1,P,L] 

<Location /s1_webconsole>
...
Header add Set-Cookie backend_server=%{SERVER}e;Path=/s1_webconsole
 ...
</Location>

Re: [users@httpd] help needed on Load balancing and environment variables scope

Posted by chalu <ch...@egenius.com>.
Andrea wrote:

> Hy everybody,
> I'm configuring Apache as a reverse proxy and I am doing loadbalancing 
> between some backend servers.
> I' am doing load balancing using mod_rewrite. My backend webapps 
> (every webapp is replicated in various servers) use cookies to mantain 
> sessions.
>  
> So my goal was to redirect every user to same server he first was 
> redirected to.
> I achieved this setting the environment variable SERVER to the server 
> name the user is first redirected to, then storing this value in a 
> cookie; all the following request of the same user are then redirected 
> to the server whose name is stored in the "backend_server" cookie.
>  
>  My question is:
> what is the scope of the SERVER environment variable ? What happens if 
> many users request simultaneusly ? Does the value of SERVER is shared 
> inconsistently ?
> I mean...may a user be redirected to the wrong server ?
>  
> Below I enclose the my config.
>  
> Any help is really appreciated.
> Thanks
> Andrea
>  
>  
> RewriteMap lb rnd:/usr/local/apache2/conf/backend.table
> RewriteCond %{HTTP_COOKIE} (^|(.+;)*)backend_server=(.+)(;?)
> RewriteRule ^/s1_webconsole/(.*)$  http://%3/webconsole/$1 
> [E=SERVER:%3,P,L] 
> RewriteCond %{HTTP_COOKIE} !(^|(.+;)*)backend_server=(.+)(;?)
> RewriteRule ^/s1_webconsole/(.*)$  to://${lb:www}/$1
> RewriteRule ^to://([^/]+)/(.*)$  http://$1/$2 [E=SERVER:$1,P,L] 
>  
> <Location /s1_webconsole>
> ...
> Header add Set-Cookie backend_server=%{SERVER}e;Path=/s1_webconsole
>  ...
> </Location>

Why not use "pound"?

Re: [users@httpd] help needed on Load balancing and environment variables scope

Posted by Joshua Slive <js...@gmail.com>.
On 5/25/05, Andrea <pa...@eng.it> wrote:
>  My question is: 
> what is the scope of the SERVER environment variable ? What happens if many
> users request simultaneusly ? Does the value of SERVER is shared
> inconsistently ? 
> I mean...may a user be redirected to the wrong server ? 

Env variables are request-specific, so you shouldn't have any problem.
 (You may be confused by the name.  Apache environment variables
aren't "real" environment variables.  See:
http://httpd.apache.org/docs-2.0/env.html )

Joshua.

---------------------------------------------------------------------
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