Re: Is it possible for haproxy to connect to backend server specified in an http header

From: Ben Timby <btimby#gmail.com>
Date: Fri, 1 Apr 2011 20:42:30 -0400


On Fri, Apr 1, 2011 at 12:24 PM, Delta Yeh <delta.yeh#gmail.com> wrote:
> Hi all,
>  When setting up a web hosting service with haproxy, there is a requirement.
> The case is :
> client----nginx-------haproxy---------------wwws
>
> client :1.1.1.1
> nginx  2.2.2.1
> haorxy:2.2.2.2
> wwws:3.3.3.1
>
> nginx sit between client and  haproxy, haproxy work in transparnt mode.
>
> client send request to  www.abc.com( 3.3.3.1) ,the request is redirect
> to nginx box.
> nginx get the original server 3.3.3.1 and add a header  x-original-to:3.3.3.1 ,
> nginx proxy request to haproxy, haproxy proxy request to the original
> www server 3.3.3.1 specified in http header "x-original-to"
>
>
> the config fragment of haproxy may like:
>
> backend wwws
>        mode http
>        server  virtual-host-server  0.0.0.0 addr_header x-original-to
>        source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1)
>
>
> so server option "addr_header x-original-to" tell haproxy  the real
> www server address to be connected to is
> specified in header "x-original-to"
>
> So my question is it possible for haproxy to do this?

Someone else can correct me if I am wrong, but I don't think this will work exactly as described. However, a similar method that would work if you have a number of known backends is to use acls to route the request.

Given two possible backends:

www1: 3.3.3.1
www2: 3.3.3.2

A configuration like:

listen http

    bind        2.2.2.2:80
    mode        http
    option      httplog
    balance     roundrobin
    acl           use-www1 hdr(x-original-to) 3.3.3.1
    acl           use-www2 hdr(x-original-to) 3.3.3.2
    use_backend www1 if use-www1
    use_backend www2 if use-www2
    server      www1 3.3.3.1:80
    server      www2 3.3.3.2:80

The acl will be set to true when the IP address matches that of the backend. The acl then determines which backend to use. You would have to write an acl and use_backend rule for each backend. It would not work for arbitrary backends. Received on 2011/04/02 02:42

This archive was generated by hypermail 2.2.0 : 2011/04/02 02:45 CEST