Re: Problem: host header keeps the IP of the HAProxy server

From: Cyril Bonté <cyril.bonte#free.fr>
Date: Sun, 14 Aug 2011 17:16:04 +0200


Le Sunday 14 August 2011 13:31:57, Ran S a écrit :
> Hi Cyril,
>
> I see, thanks for that.
> So, will the correct way be to configure two different backends and include
> the reqrep for each one of them.
> But how will I get the listen or frontend node to load balance between two
> different backend nodes? I can't find the configuration to do that... is it
> possible?

Well, haproxy is not designed to load balance between backends, but there are several workarounds (some of them are less elegant than the others).

For your issue, I don't know all about your configuration so maybe it won't work, but first, can you check if you can unconditionally replace the Host header with 127.0.0.1 ? Maybe that could do the trick.

   reqrep ^Host:\ 172.31.0.103 Host:\ 127.0.0.1

One other workaround is to decide to not load balance but switch to a second backend under certain conditions (for example when the first backend exceeds a # of connections).

frontend http-in

   bind :80
   mode http
   option httpclose

   use_backend backend2 if { be_conn(backend1) gt 100 }    default_backend backend1

backend backend1

   mode http

   reqrep ^Host:\ 172.31.0.103 Host:\ 172.31.0.104    server node1 172.31.0.104:85

backend backend2

   mode http

   reqrep ^Host:\ 172.31.0.103 Host:\ 172.31.0.118    server node2 172.31.0.118:85

Another solution is to add a second level of proxies in haproxy :

listen http-in

   bind :80
   mode http
   option httpclose

   server pnode1 127.0.0.1:8104
   server pnode2 127.0.0.1:8118

listen proxy104

   bind 127.0.0.1:8104
   mode http
   option httpclose

   reqrep ^Host:\ 172.31.0.103 Host:\ 172.31.0.104    server node1 172.31.0.104:85

listen proxy118

   bind 127.0.0.1:8118
   mode http
   option httpclose

   reqrep ^Host:\ 172.31.0.103 Host:\ 172.31.0.118    server node2 172.31.0.118:85

This is just some ideas (not tested), or you can try to add some conditions directly in your apache configuration.

Hope this helps.

-- 
Cyril Bonté
Received on 2011/08/14 17:16

This archive was generated by hypermail 2.2.0 : 2011/08/14 17:30 CEST