1 Request header is too large
從字面意思可知,是請求頭過大,設定connector的maxHttpHeaderSize為大點的值即可,單位byte,默認值:8192 (8 KB),官方檔案原文如下:http://tomcat.apache.org/tomcat-9.0-doc/config/http.html#Standard_Implementation
maxHttpHeaderSize :
The maximum size of the request and response HTTP header, specified in bytes. If not specified, this attribute is set to 8192 (8 KB).
注意,官方檔案并沒有說明如何將該值設定為無限制,所以盡量不要將其設定為負數以免程式出錯,
示例如下在tomcat檔案夾下的conf檔案中的server.xml
<!--設定maxHttpHeaderSize限制為16KB,可根據需求適當加到更大-->
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"
maxHttpHeaderSize="16384"/>
2 Request Entity Too Large
從字面意思可知,是請求體過大,多見于檔案上傳時觸發,設定connector的maxPostSize為大點的值即可,單位byte,默認值:2097152 (2 megabytes),若想將其設為無限制,則將其設定為負數即可,網上解決方案大多說設定為0,這是錯的,設定為0會導致tomcat截斷post的引數,導致后臺接收到的引數全都是null,官方檔案原文如下:http://tomcat.apache.org/tomcat-9.0-doc/config/http.html#Common_Attributes
maxPostSize : The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. If not specified, this attribute is set to 2097152 (2 megabytes).
注意,官方檔案說的是less than zero,也就是說設定為小于0的值才是設定maxPostSize為無限制,網上的大多數解決方法說的設定為0是錯的,
<!--設定maxPostSize限制為200MB-->
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"
maxPostSize="209715200"/>
3 綜合方案
綜上,避免 Request header is too large和Request Entity Too Large的最好的配置就是同時配置倆屬性為較大的值,避免不必要的麻煩,示例如下:在tomcat檔案夾下的conf檔案中的server.xml
<!--設定maxPostSize限制為200MB,設定maxHttpHeaderSize限制為16KB-->
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"
maxPostSize="209715200" maxHttpHeaderSize="16384"/>
4 懶人方案(不建議)
任何東西太大都不好,會造成不必要的麻煩,如果無法估計配置的大小,可以設定為不限制大小
- 在tomcat檔案夾下的conf檔案中的server.xml 配置中添加:
- maxPostSize="-1" //-1 表示不限制大小
- maxPostSize:指定POST方式請求的最大量,沒有指定默認為2097152,
- maxHttpHeaderSize =“102400”
- maxHttpHeaderSize:HTTP請求和回應頭的最大量,以位元組為單位,默認值為4096位元組
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"
maxPostSize="-1" maxHttpHeaderSize="102400"/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/4839.html
標籤:其他
上一篇:Canvas悟空推箱子
