Hello Team
I’m working on a setup where I need to dynamically set the Host header based on the backend server that HAProxy selects upon load balancing. My backend configuration looks like this:
backend be
mode http
option forwardfor
balance leastconn
option httpchk
http-check send meth GET uri /health
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
http-request add-header X-Forwarded-Host %[req.hdr(host)]
http-request set-header Host [SERVER_NAME]
server srv-instance1.com srv-instance1.com:443 check inter 10s fastinter 1s downinter 1m resolvers nimbus init-addr last,libc,none ssl verify none check-sni srv-instance1.com sni str(srv-instance1.com) alpn h2 check-alpn h2
server srv-instance2.com srv-instance2.com:443 check inter 10s fastinter 1s downinter 1m resolvers nimbus init-addr last,libc,none ssl verify none check-sni srv-instance2.com sni str(srv-instance2.com) alpn h2 check-alpn h2
HAProxy version: 2.6.12
And I am using grpc http2 with tls
In this setup, I want the Host header to match the name of the server that HAProxy has chosen (e.g., srv-instance1.com or srv-instance2.com)
What I’ve Tried:
I attempted to use http-send-name-header to set the Host header, but it doesn’t seem to be working in my scenario.
Also variables like srv_name and srv_id also does not help.
Question:
How can I set the Host header dynamically based on the backend server that HAProxy selects?
Is there a way to achieve this ? Any guidance or suggestions would be greatly appreciated!
Thanks in advance!