HAProxy community

Trafic routing based on client IP from X-Forwarded-For header


I have problem. I must make traffic load balancing between two internal machines.

There is requirement - traffic must be routed basing on client IP in such way that from one IP client connects always to the same backend server.

It is simple, but traffic from clients goes from external proxy service and the source IP is always the same. The originial source IP is only available in X-Forwarde-For HTTP header.

Is it possible to user XFF header in HAProxy?

Thanks in advance.


As long as you trust the up-stream proxy then yes:
You can use the client source IP address from the XFF header in a stick table.
See the example at the bottom of this blog:

Which will try and stick on XFF first, then fallback to normal source if XFF doesn’t exist.