KMG
KMG

Reputation: 927

set frontend_ip as source IP for backend

I have a server with multiple IP configured on it ( as virtual IP on eth0). I'm using Haproxy for Load balacing. Each IP has been configured/pointed to different domain name and All requests that comes to each IP address is being forwarded to different backend server by using haproxy.

Issue here, all outgoing traffic from haproxy is pass through main interface IP [ by default]. I just wanted to set source ip for backend connection.

I tried the below config, its not working. Any idea ?

backend  web1
       server ss2 10.11.12.13:80 source ${frontend_ip} 

frontend new1
       bind 10.11.13.15:8080
       mode tcp
       use_backend web1

Upvotes: 0

Views: 1412

Answers (1)

Ianthe the Duke of Nukem
Ianthe the Duke of Nukem

Reputation: 1761

You only have 1 IP in your question so I can't say for sure. But if you have multiple virtual IPs and want to serve different backends, you need to create one frontend each at least. Like this:

frontend new1
    bind 10.11.13.15:80
    ...
    acl is_new1domain hdr(host) -i new1.domain.com
    use_backend web1 if is_new1domain

frontend new2
    bind 10.11.13.16:80
    ...
    acl is_new2domain hdr(host) -i new2.domain.com
    use_backend web2 if is_new2domain

backend web1
    ...
    source 10.124.13.15

backend web2
    ...
    source 10.124.13.16

Actually, if you don't have any other rules to parse, just use Layer4 to proxy/balance. Like this:

listen new1
    bind 10.11.12.15:80
    server ss1 10.11.12.90:8080 check
    server ss2 10.11.12.91:8080 check
    server ss3 10.11.12.92:8080 check
    source 10.124.12.15

listen new2
    bind 10.11.12.16:80
    server ss4 10.11.12.80:8080 check
    server ss5 10.11.12.81:8080 check
    server ss6 10.11.12.82:8080 check
    source 10.124.12.16

Upvotes: 1

Related Questions