Hi Cyril,

On Sat, Mar 17, 2012 at 12:46:03AM +0100, Cyril Bonté wrote:
> Hi,
> 
> Le 15/03/2012 08:39, wsq003 a écrit :
> >Thanks, Carlo. It works.
> >But can it be simpler? such as:
> >frontend http
> >bind :80
> >mode http
> >default_backend pool
> >
> >backend pool
> >server s01 2.3.4.1:80
> >server s02 2.3.4.2:80
> >server s03 2.3.4.3:80
> >use_server s01 if { src 217.192.7.0/24 }
> 
> If you're in http mode, you may use some tricks to emulate this (Note 
> that I've never tested it in production).
> 
> First, use "cookie" keyword without any actions (no prefix, insert or 
> rewrite option) :
> 
>   cookie LB
> 
> Add cookie values on each server :
> 
>   server s01 2.3.4.1:80 cookie s01
>   server s02 2.3.4.2:80 cookie s02
>   server s03 2.3.4.3:80 cookie s03
> 
> Then enumerate the acls you want to reach a specific server :
> 
>   acl s01 src 217.192.7.0/24
>   acl s02 ...
> 
> 
> Ask haproxy to add a fake cookie depending on the acl matching :
> 
>   reqadd Cookie:\ LB=s01 if s01
> 
> And maybe you want to force the persistence for such conditions :
> 
>   force-persist if s01 || s02 ...
> 
> To sum up, this gives :
> 
> backend pool
>   mode http
>   # use option httpclose or option http-server-close
>   ...
>   cookie LB
> 
>   server s01 2.3.4.1:80 cookie s01
>   server s02 2.3.4.2:80 cookie s02
>   server s03 2.3.4.3:80 cookie s03
> 
>   acl s01 src 217.192.7.0/24
>   acl s02 ...
> 
>   reqadd Cookie:\ LB=s01 if s01
> 
>   force-persist if s01 || s02 ...
> 
> Consider this experimental unless someone confirms he already used this 
> in production ;-)

Yes it works because req* rules are processed before cookie inspection.
I've used something about similar in some setups, which consisted in
renaming a header "x-something: YZ" to "cookie: SRV=YZ" to get the same
behaviour.

I think I should update the diagram which details all the processing steps
because a number of additions were made and not updated there.

Regards,
Willy


Reply via email to