How to configure HAProxy to include host headers


Example we have 2 nodes for load balancing:

node1.tutorialspots.com
node2.tutorialspots.com

We have 2 methods to configure HAProxy to include host headers

Method 1:

backend nodes
    mode http
    balance roundrobin
    option forwardfor
    http-send-name-header Host
    server tutorialspots.com node1.tutorialspots.com:80
    server tutorialspots.com node2.tutorialspots.com:80

Method 2:

backend nodes
    mode http
    balance roundrobin
    option forwardfor
    http-request set-header Host node1.tutorialspots.com if { srv_id 1 }
    http-request set-header Host node2.tutorialspots.com if { srv_id 2 }
    server web01 node1.tutorialspots.com:80
    server web02 node2.tutorialspots.com:80

Method 3:

backend nginx
    mode http
    balance roundrobin
    option forwardfor    
    http-request set-header Host %[req.hdr(Host)]
    server web01 node1.tutorialspots.com:80
    server web02 node2.tutorialspots.com:80

1 Comment

Leave a Reply