Making HAProxy Pass a Host Name in HTTPCHECK

I am trying to perform HTTP Checks in HAProxy with a specific host name.

Here is a snippet from my backend configuration:

option httpchk HEAD / HTTP/1.1\r\nHost: example.com
http-check expect rstatus (2)[0-9][0-9]

When I view the IIS logs on the server being checked, the host name (cs-host) is blank:

#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2016-04-15 20:24:09 W3SVC3 123.123.123.123 HEAD / - 80 - 456.456.456.456 - - - 302 0 0 365 45 14

Compared to a request from a browser, where the host name is visible:

#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2016-04-15 12:29:18 W3SVC3 123.123.123.123 GET / - 80 - 456.456.456.456 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - example.com 302 0 0 397 249 1959

I am using HA-Proxy version 1.5.14 2015/07/02

How do I get HAProxy to send a host name with the HTTP Check?


Solution 1:

You might need to escape the space before "example.com", i.e.

option httpchk HEAD / HTTP/1.1\r\nHost:\ example.com

Note the backslash before "example.com". Alternatively, you might try adding:

http-send-name-header Host

in that backend config.

Hope this helps!