HAProxy 健康检查不工作但 CURL returns 200 OK
HAProxy health check not working but CURL returns 200 OK
我有一个配置了以下后端的 HAProxy 健康检查:
backend php_servers
http-request set-header X-Forwarded-Port %[dst_port]
option httpchk get /health
http-check expect status 200
server php1 internal_ip:80 check
HAProxy 未启用服务器,但在使用 CURL 时我收到 200 OK 响应。
Command: curl -I internal_ip/health
Response:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 01 Dec 2016 20:53:48 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Access-Control-Allow-Origin: api.flex-appeal.nl
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-transform
为什么 HAProxy 无法将服务器识别为 "UP"?看来我可以正常连接。
正确的 HTTP 动词是 GET
,而不是 get
:
option httpchk GET /health
您还可以 check/enable stats page:在 LastChk
列中您会看到 为什么 检查失败。就我而言,我得到了 501 Not Implemented
响应。
我可以通过执行与 HAProxy 相同的请求来重现它:
$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get /health HTTP/1.0
HTTP/1.1 501 Not Implemented
Date: Thu, 01 Dec 2016 21:53:09 GMT
Server: Apache/2.4.23 (Unix) PHP/7.0.13
[...]
我有一个配置了以下后端的 HAProxy 健康检查:
backend php_servers
http-request set-header X-Forwarded-Port %[dst_port]
option httpchk get /health
http-check expect status 200
server php1 internal_ip:80 check
HAProxy 未启用服务器,但在使用 CURL 时我收到 200 OK 响应。
Command: curl -I internal_ip/health
Response:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 01 Dec 2016 20:53:48 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Access-Control-Allow-Origin: api.flex-appeal.nl
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-transform
为什么 HAProxy 无法将服务器识别为 "UP"?看来我可以正常连接。
正确的 HTTP 动词是 GET
,而不是 get
:
option httpchk GET /health
您还可以 check/enable stats page:在 LastChk
列中您会看到 为什么 检查失败。就我而言,我得到了 501 Not Implemented
响应。
我可以通过执行与 HAProxy 相同的请求来重现它:
$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
get /health HTTP/1.0
HTTP/1.1 501 Not Implemented
Date: Thu, 01 Dec 2016 21:53:09 GMT
Server: Apache/2.4.23 (Unix) PHP/7.0.13
[...]