1. 程式人生 > 其它 >Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level

Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level

雲伺服器很久沒管過了,今天去看了下雲伺服器日誌,不看不知道,一看嚇一跳。

日誌裡竟然是一排的報錯,再翻下此前的日誌,每天都報一個錯誤:

    [http-nio-80-exec-10] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
    java.lang.IllegalArgumentException: Request header is too large
        at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:
790) at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:454) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:269) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:
893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

隨後我去查了一下,網友的說法大致為以下幾種:

1、Tomcat 的 header 緩衝區不夠

需要在server.xml(tomcat根目錄下的conf目錄)中增加maxHttpHeaderSize,單位為KB

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               maxHttpHeaderSize="8192"/>

2、Url頭用的是 https

將 https 改成 http 即可(未實驗)

3、Url傳參時攜帶了特殊符號

json傳輸的時候包含了{},這就是原因所在、

因為tomcat7某個版本之後,增加了一個新特性,就是嚴格按照RFC3986規範進行訪問解析

而RFC3986規範定義了Url中,只允許包含:英文字母(a-zA-Z)數字(0-9)-_.~ 4個特殊字元

以及所有保留字元(RFC3986中指定了以下字元為保留字元:!*'();:@&=+$,/?#[])

解決方法其實很簡單,可以通過修改 tomca t的 catalina.properties 的最後一行改為

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

允許{}即可