413 Request Entity Too Large
Asked Answered
T

6

51

I use nginX/1.6 and laravel when i posted data to server i get this error 413 Request Entity Too Large. i tried many solutions as bellow

1- set client_max_body_size 100m; in server and location and http in nginx.conf.
2- set upload_max_filesize = 100m in php.ini
3- set post_max_size = 100m in php.ini

After restarting php5-fpm and nginx the problem still not solved

Tendinous answered 28/10, 2014 at 12:39 Comment(3)
Make sure you are not overwriting client_max_body_size values in included config files, that is if your nginx.conf, includes other .conf files.Diskson
i checked all .conf files and ensured thatTendinous
i solved the problem by remove client_max_body_size from locationTendinous
A
107

Add ‘client_max_body_size xxM’ inside the http section in /etc/nginx/nginx.conf, where xx is the size (in megabytes) that you want to allow.

http {
      client_max_body_size 20M;         
}
Aimless answered 12/1, 2015 at 5:44 Comment(3)
could you give full dir? I can't find itThanet
I think you need to restart ngnix sudo service nginx restartWomanizer
nginx docs: nginx.org/en/docs/http/…Goodbye
V
19

I had the same issue but in docker. when I faced this issue, added client_max_body_size 120M; to my Nginx server configuration,

nginx default configuration file path is /etc/nginx/conf.d/default.conf

server {
    client_max_body_size 120M;
    ...

it resizes max body size to 120 megabytes. pay attention to where you put client_max_body_size, because it effects on its scope. for example if you put client_max_body_size in a location scope, only the location scope will be effected with.

after that, I did add these three lines to my PHP docker file

RUN echo "max_file_uploads=100" >> /usr/local/etc/php/conf.d/docker-php-ext-max_file_uploads.ini
RUN echo "post_max_size=120M" >> /usr/local/etc/php/conf.d/docker-php-ext-post_max_size.ini
RUN echo "upload_max_filesize=120M" >> /usr/local/etc/php/conf.d/docker-php-ext-upload_max_filesize.ini

since docker PHP image automatically includes all setting files from the path (/usr/local/etc/php/conf.d/) into php.ini file, PHP configuration file will change by these three lines and the issue must disappear

Villareal answered 10/9, 2019 at 8:17 Comment(0)
U
3

Even after adding client_max_body_size 20M; in nginx.conf file, I get the same error in my Laravel app.Later I found the limit referred to in the php.ini. Go to /etc/php/<your-php-version>/fpm and edit the following lines in the php.ini file .

upload_max_filesize = 20M
post_max_size = 20M

increase the limit size as per your app need.Dont forget to Restart PHP-FPM by sudo service php8.2-fpm restart

Undergraduate answered 14/12, 2023 at 11:17 Comment(0)
S
2

I am using Docker and PHP 7.4 and I faced this issue too.

Just added a line to the file *.conf inside docker/php74/ directory.

server {
    client_max_body_size 100M;
    ...
}
Starofbethlehem answered 29/5, 2020 at 14:56 Comment(1)
If you read carefully what AhmedShawky has asked, It seems that he had already tried that.Rafe
V
0

Solved it for me when editing not only in /etc/php/<php-version>/cli/php.ini, but in /etc/php/<php-version>/fpm/php.ini too with the following values:

upload_max_filesize = 20M

post_max_size = 20M

After this, restart the fpm. sudo service php<php-version>-fpm restart

Vandalism answered 17/6 at 19:34 Comment(0)
J
0

I've spent several hours trying to rectify this issue and adding the upload_max_filesize and post_max_size to the php.ini or /etc/nginx/nginx.conf was not helping.

How did I resolved this:

  1. I made sure that I don't set the parameters only to the location blocks, but also to the server blocks and restarted the nginx service.
  2. However, this was not working yet, what made it finally working was to set the fastcgi_param in sites-available:

fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";

Check these posts:

https://serverfault.com/questions/611239/increase-php-fpms-max-upload-post-size

Particularly this answer if nothing else helps:

https://serverfault.com/a/827755/764823

Josi answered 20/7 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.