Haproxy set Host Header per origin Server

Jay asked:

We are trying to set host header per origin server, we can set per back end, but we are using default names on Azure app services, and as such the service will only respond to its own hostname, for example

http-request set-header Host example1.azurewebsites.net # for origin server 1

http-request set-header Host example2.azurewebsites.net # for origin server 2

However, can’t see any way to set this on the origin server itself

server svr_example1 xx.xx.xx.xx:443 id 10 weight 10 maxconn 25 cookie exa1 check ssl verify none

server svr_example2 xx.xx.xx.xx:443 id 10 weight 10 maxconn 25 cookie exa1 check ssl verify none

Something like

server svr_example1 xx.xx.xx.xx:443 id 10 weight 10 maxconn 25 cookie exa1 check ssl verify none http-request set-header Host example1.azurewebsites.net

server svr_example2 xx.xx.xx.xx:443 id 11 weight 10 maxconn 25 cookie exa1 check ssl verify none http-request set-header Host example2.azurewebsites.net

Using haproxy version 1.8.28

My answer:


They are separate directives and you must put them on separate lines, e.g.:

backend svr_example1
        server svr_example1 xx.xx.xx.xx:443 id 10 weight 10 maxconn 25 cookie exa1 check ssl verify none
        http-request set-header Host example1.azurewebsites.net

Note that you can only do this when HAProxy terminates TLS. You cannot do this if you are passing through TLS.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.