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

本文介绍了一种Tengine 2.2.2版本中的健康检查配置案例,详细解释了因缺少Host头部导致服务器返回400错误的问题及解决办法,并分享了一个有效的配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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千台以上的服务器并在配置的时候出现了错误,就可能需要扩大该内存的大小。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值