4
0

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 1 year has passed since last update.

【nginx】リクエストボディのサイズ上限を変更する

Posted at

結論

nginxをWebサーバに採用、かつWebアプリケーションにファイルアップロードなどの機能を持たせる場合はclient_max_body_sizeを適切な値に設定すること。

理由

nginxで受け付けるリクエストボディのサイズ上限を設定する、client_max_body_sizeのデフォルト値は1MBのため。
デフォルト値のままにしてデフォルト値を超えるファイルをアップロードしようとすると、HTTPステータス413 Payload Too Largeが返ってきてしまいます。

設定例

/etc/nginx/nginx.conf
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    client_max_body_size 100m; # <- ここ

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
                                                   ︙

終わりに

あまりWebサーバの設定を触ることがなかったので勉強になりました。

参考

http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
https://developer.mozilla.org/ja/docs/Web/HTTP/Status/413

4
0
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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?