6

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?

Fenton
  • 244
  • 2
  • 4
  • 16
  • 2
    Do you 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. – Castaglia Apr 15 '16 at 23:17
  • @Castaglia... hint -> Turn your comment into an answer - removing the space fixed the problem instantly! Thank you! – Fenton Apr 16 '16 at 08:25
  • Similar, but a bit more complicated question (involving different hostnames): https://serverfault.com/questions/594669 – Attila Csipak Mar 06 '24 at 12:05

1 Answers1

9

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!

Castaglia
  • 3,379
  • http-send-name-header does not affect the HTTP health checks. It only affects the HTTP requests forwarded by the proxy. In HAProxy 1.5.x the only way to add the Host header to the health check HTTP requests is the ugly hacking of option httpchk. – Attila Csipak Mar 06 '24 at 11:50