We can configure HAProxy to be a transparent proxy by using the guide here, where one of the steps says

...to put the backend servers in a different subnet to the front end clients and make sure that the default gateway points back at the HAProxy load balancer.

However when we need to have 2 transparent HAProxy in front of our balanced servers (for redundancy), it seems like this wont work as we can only set one gateway for our balanced servers.

What will be the correct way to setup the system such that we can have 2 transparent HAProxy infront of the balanced servers? The main reason for having transparent proxies is the need to find the client's IP addresses over TCP.


There are couple of approaches you can use here.

First one is to have floating IP address set between two haproxy machines, and use something like ucarp, keepalived or RedHat Cluster Suite to migrate the IP address between two hosts. That way when one host goes down, another will pick up the IP and your web servers will only have 1 gateway ip.

Another approach - if you use HTTP, is to do 'mode http' instead of 'mode tcp' load balancing, and use X-HTTP-Forwarded-For. You will have to reconfigure your haproxy and your backends. Backends will have to use something like mod_rpaf/mod_extract_forwarded to extract IP from the HTTP header, and haproxy will have to use directive:

option forwardfor       except

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.