使HAProxy通过HTTPCHECK中的主机名

我正在尝试使用特定主机名在HAProxy中执行HTTP检查。

这里是我的后端configuration的一个片段:

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

当我查看正在检查的服务器上的IIS日志时,主机名( cs-host )为空:

 #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 

与来自浏览器的请求相比,主机名可见:

 #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 

我正在使用HA-Proxy版本1.5.14 2015/07/02

如何让HAProxy通过HTTP Check发送主机名?

你可能需要跳过“example.com”之前的空格,

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

请注意“example.com”之前的反斜杠。 或者,您可以尝试添加:

 http-send-name-header Host 

在后端configuration。

希望这可以帮助!