Tengine2.2.2 健康检查http1.1 服务器报错400 Bad Request 问题分析

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nimasike/article/details/81169811

Tengine2.2.2官方健康检查示例

check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_keepalive_requests 100;
check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;

结果一直报错,通过抓包工具发现服务器端返回400 Bad Request

查询http1.1协议发现请求当中必须包含host请求头,(其值可以为空),否则服务器会返回400 Bad Request错误

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

A client MUST include a Host header field in all HTTP/1.1 request messages . If the requested URI does not include an Internet host name for the service being requested, then the Host header field MUST be given with an empty value. An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field.

我修改后的示例

check interval=3000 rise=2 fall=5 timeout=2000 type=http;
check_keepalive_requests 100;
check_http_send "GET / HTTP/1.1\r\nHost:\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;

其中加上了host请求头,值可以为空。

测试无误,nginx与tomcat使用http1.1长连接进行健康检查.

有个配置check_shm_size size

所有的后端服务器健康检查状态都存于共享内存中,该指令可以设置共享内存的大小。默认是1M,如果你有1千台以上的服务器并在配置的时候出现了错误,就可能需要扩大该内存的大小。

猜你喜欢

转载自blog.csdn.net/nimasike/article/details/81169811