[已解决] 记录一次排查错误Invalid character found in the HTTP protocol

环境

Tomcat 8.x

报错

Invalid character found in the HTTP protocol [HTTP/1.1 Connection:]

分析

查看localhost_access_log.txt发现:

HEAD / 400

都是HEAD 请求,且返回都是400,毕竟HTTP协议的字符不正确。

调研

How to solve "Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]"?

这篇文章说了HTTP协议格式是这样的:

"GET " + path + " HTTP/1.1\r\n"

推测

推测有个崽写了这样的请求,缺少一个换行

"HEAD / HTTP/1.1 Connection"

破案

最终发现是 nginx配置了一个健康检查:

check_http_send "HEAD / HTTP/1.1 Connection: keep-alive ";

正确写法

check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive ";

当然有没有这个URL PATH 就是另一个回事了,如果404 Not Found,也还是返回4xx的错误信息。

posted @ 2023-04-10 18:49  一杯半盏  阅读(468)  评论(0编辑  收藏  举报