HAProxy community

[SOLVED] Redirect to backend using the requested IP



I am using HAProxy 1.8. My haProxy receives http requests on 2 interfaces. I would need to redirect those requests to backend depending on the requested IP.

With an example:

Field A for domain1 is linked to IP1
Field A for domain2 is linked to IP2

HaProxy is listening on both IP1 & IP2 for requests (in my config file, in frontend section, I have bind *:80)

I defined 2 backends:
backend1 send requests on server1 and port 80
backend2 send requests on server1 and port 81

Is this possible using ACL to redirect requests from domain1 to server1 and requests from domain2 to server2?

I guess I can do it by creating multiple frontend sections with a bind on a specific IP but I wanted to know if it would be possible to do it with acl.

Thx in advance!


As you say, you would do that with a dedicated frontend, but if you want to do it with ACL you can, just access the dst variable (see dst).



So if I understand correctly, I can create a rule like:

acl rule1 dst IP1
use_backend backend1 if rule1

Is this correct? (IP1 will be replaced by a real IPv4).


This does work well!