TomcatのmaxPostSizeとmaxParameterCountには注意!! | Ohjiro's Note

Ohjiro's Note

<オージロウの奮闘ノート> これはオージロウが奮闘した日々の大切な記録です。

こんにちは、オージロウです。

Tomcatの「maxPostSize」と「maxParameterCount」は意識的にチューニングすることをオススメします。特に業務系のシステム導入においては、POSTサイズとパラメータ数が上限に達することもあるはず。必ず見直し項目としておきましょうね。

こんなエラーが発生した場合


More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.

原因


ブラウザからPOST送信されたパラメータ数が上限に達した。このままではエラーは解消されませんので「maxParameterCount」を再設定します。併せて「maxPostSize」も見直ししましょう。

ちなみにTomcatのドキュメントでは


http://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html

maxParameterCount (初期値:10000パラメータ)
The maximum number of parameter and value pairs (GET plus POST) which will be automatically parsed by the container. Parameter and value pairs beyond this limit will be ignored. A value of less than 0 means no limit. If not specified, a default of 10000 is used. Note that FailedRequestFilter filter can be used to reject requests that hit the limit.

maxPostSize (初期値:2MB)
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 or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

具体的な設定見直し結果(server.xml)


<Connector port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443"
    useBodyEncodingForURI="true"
    maxPostSize="10485760"  ⇒ 初期値:2MB→10MB
    maxParameterCount="50000" />  ⇒ 初期値:10000→50000

結構、見落とすことが多いですよね。初期導入時が肝心。<つづく>