2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Webアプリのファイルアップロードで413 Request Entity Too Largeを回避した話

Last updated at Posted at 2020-12-24

以下のようなリバースプロキシ構成でJSPとか使ってWebアプリケーションを開発しているのですが、アプリケーションについているファイルアップロード機能で「413 Request Entity Too Large というエラーが出てファイルのアップロードに失敗する」という問題が発生しました。

[client]----->[nginx]----->[Tomcat]

詳しく聞いてみると、いつもよりちょっと大きい1.5MB程度のファイルをアップロードしたところこのエラーが出たとのこと。

たしか、Tomcatにこういう制限があったなと思いだして、マニュアルを見てみると。

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). Note that the FailedRequestFilter can be used to reject requests that exceed this limit.

デフォルトで2MB... 2メガバイトまではいけるのにどうして??
と暫く考えましたが、前段のnginxにも同様の設定があり、

Syntax: client_max_body_size size;
Default: client_max_body_size 1m;

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

こっちはもっと小さく、デフォルト1MB ... 1メガバイト でした。
ここでエラーになっていたわけですね。

そこで、nginxの設定ファイルに client_max_body_size を足して再起動し、無事アップロードできるようになりました!

nginx.conf
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;
        client_max_body_size 10M;
        ....

通り道にも気を付けましょうというお話でした。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?