LoginSignup
12
7

More than 3 years have passed since last update.

Nginxのエラー「413 Request Entity Too Large」の対処

Posted at

問題

Nginxを使ったアプリにおいて少し大きめのファイルをアップロードしたところ、このようなエラーが
image.png

ファイルサイズが大きすぎるためこのようなエラーが出るようです。

Nginxはデフォルトでは最大のアップロードのサイズが1MBとなっているようです。

対処法

Nginxの設定を変更

自分は環境構築にDockerを利用しているのでdocker/nginx/default.confを編集します。

default.conf
server {
    listen       0.0.0.0:80;
    server_name  localhost;
    charset      utf-8;
    client_max_body_size 10M; #追加

serverブロック内にclient_max_body_sizeの項目を追加またはサイズの変更をします。

php.iniの設定を変更

自分の場合はphp側の変更をしなくても行けたのですが、必要な場合もあるようなのでメモ程度に書きます。
post_max_sizeとupload_max_filesizeの項目を編集します。

php.ini
post_max_size = 10M
upload_max_filesize = 10M

設定を変更したらnginxを再起動します。

12
7
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
12
7