有人能更深入地解释一下 HAproxy 健康检查配置吗?我不太明白这部分
option httpchk HEAD / HTTP/1.1
我在应用此代码时一直收到 400 错误。提前致谢
答案1
您收到 HTTP 400 状态代码的原因有多种。其中之一可能是您的后端服务器确实返回了该响应。确保情况并非如此。
尝试添加主持人HTTP 协议版本之后的标头按照建议文档。
option httpchk <method> <uri> <version>
<method> is the optional HTTP method used with the requests. When not set,
the "OPTIONS" method is used, as it generally requires low server
processing and is easy to filter out from the logs. Any method
may be used, though it is not recommended to invent non-standard
ones.
<uri> is the URI referenced in the HTTP requests. It defaults to " / "
which is accessible by default on almost any server, but may be
changed to any other URI. Query strings are permitted.
<version> is the optional HTTP version string. It defaults to "HTTP/1.0"
but some servers might behave incorrectly in HTTP 1.0, so turning
it to HTTP/1.1 may sometimes help. Note that the Host field is
mandatory in HTTP/1.1, and as a trick, it is possible to pass it
after "\r\n" following the version string.
请注意,您必须用 分隔版本和每个传递的标头\r\n
,并且任何空格字符都必须用反斜杠转义。否则它将被解析为选项配置指令的下一个参数,这可能导致错误的配置文件。
例子:
option httpchk HEAD / HTTP/1.1\r\nHost:\ domain.example.com