413 Request Entity Too Large - File Upload Issue

PhpNginxApache2

Php Problem Overview


I am trying to upload 30MB file on my server and its not working.

  1. When I upload 30MB file, the page loads "Page Not Found"

  2. When I upload a 3MB file, I receive "413 Request Entity Too Large" with nginx/0.6.32

I am trying to find nginx so I can increase "client_max_body_size" but I am unable to find nginx installed on my server. I even tried running:

vi /etc/nginx/nginx.conf

or

vi /usr/local/nginx/conf/nginx.conf

to check if the config file exists, but I couldnt find it on my server.

Is there anyway to resolve this issue? Or do I have to installed nginx on my server.

EDIT:

I have made all necessary changes in my php.ini files,

post_max_size 128M
upload_max_filesize 100M
memory_limit 256M

Thanks, Raju

Php Solutions


Solution 1 - Php

Source: http://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/

Edit the conf file of nginx:

nano /etc/nginx/nginx.conf

Add a line in the http, server or location section:

client_max_body_size 100M;

Doen't use MB it will not work, only the M!

Also do not forget to restart nginx

systemctl restart nginx

Solution 2 - Php

-in php.ini (inside /etc/php.ini)

 max_input_time = 24000
 max_execution_time = 24000
 upload_max_filesize = 12000M
 post_max_size = 24000M
 memory_limit = 12000M

-in nginx.conf(inside /opt/nginx/conf)

client_max_body_size 24000M

Its working for my case

Solution 3 - Php

First edit the Nginx configuration file (nginx.conf)

Location: sudo nano /etc/nginx/nginx.conf

Add following codes:

http {
        client_max_body_size 100M;
}

Then Add the following lines in PHP configuration file(php.ini)

Location: sudo gedit /etc/php5/fpm/php.ini

Add following codes:

memory_limit = 128M 
post_max_size = 20M  
upload_max_filesize = 10M

Solution 4 - Php

sudo nano /etc/nginx/nginx.conf

Then add a line in the http section

http {
    client_max_body_size 100M;
}

don't use MB only M.

systemctl restart nginx

then for php location

sudo gedit /etc/php5/fpm/php.ini

for nowdays maximum use php 7.0 or higher

sudo nano /etc/php/7.2/fpm/php.ini     //7.3,7.2 or 7.1 which php you use

check those increasing by your desire .

memory_limit = 128M 
post_max_size = 20M  
upload_max_filesize = 10M

restart php-fpm

service php-fpm restart 

Solution 5 - Php

I add the changes directly to my virtualhost instead the global config of nginx, like this:

   server {
     client_max_body_size 100M;
     ...
   }

And then I change the params in php.ini, like the comments above:

   max_input_time = 24000
   max_execution_time = 24000
   upload_max_filesize = 12000M
   post_max_size = 24000M
   memory_limit = 12000M

and what you can not forget is to restart nginx and php-fpm, in centos 7 is like this:

  systemctl restart nginx
  systemctl restart php-fpm

Solution 6 - Php

Please enter domain nginx file :

nano /etc/nginx/sites-available/domain.set

Add to file this code

client_max_body_size 24000M;

If you get error use this command

nginx -t

Solution 7 - Php

I got the same error and fixed it with the below steps.

  1. At first, edit the nginx.conf file.

    vi /etc/nginx/nginx.conf

At the HTTP section, added the below line.

http {

    client_max_body_size 100M;
}

2. Finally restarted Nginx with the below command.

systemctl restart nginx

Solution 8 - Php

Assuming that you made the necessary changes in your php.ini files:

You can resolve the issue by adding the following line in your nginx.conf file found in the following path:

/etc/nginx/nginx.conf

then edit the file using vim text editor as follows:

vi /etc/nginx/nginx.conf

and add client_max_body_size with a large enough value, for example:

client_max_body_size 20MB;

After that make sure you save using :xi or :wq

And then restart your nginx.

That's it.

Worked for me, hope this helps.

Solution 9 - Php

I got the upload working with above changes. But when I made the changes I started getting 404 response in file upload which lead me to do further debugging and figured out its a permission issue by checking nginx error.log

Solution:

Check the current user and group ownership on /var/lib/nginx.

$ ls -ld /var/lib/nginx

drwx------. 3 nginx nginx 17 Oct 5 19:31 /var/lib/nginx

This tells that a possibly non-existent user and group named nginx owns this folder. This is preventing file uploading.

In my case, the username mentioned in "/etc/nginx/nginx.conf" was

user vagrant; 

Change the folder ownership to the user defined in nginx.conf in this case vagrant.

$ sudo chown -Rf vagrant:vagrant /var/lib/nginx

Verify that it actually changed.

$ ls -ld /var/lib/nginx
drwx------. 3 vagrant vagrant 17 Oct  5 19:31 /var/lib/nginx

Reload nginx and php-fpm for safer sade.

$ sudo service nginx reload
$ sudo service php-fpm reload

The permission denied error should now go away. Check the error.log (based on nginx.conf error_log location).

$ sudo nano /path/to/nginx/error.log

Solution 10 - Php

Open file/etc/nginx/nginx.conf Add or change client_max_body_size 0;

Solution 11 - Php

Use:

php -i

command or add:

phpinfo();

to get the location of configuration file.

Update these variables according to your need and server

max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M

On Linux you will need to restart nginx / apache and phpfpm service so the new ini settings are loaded. On xampp, ammps you can restart these from control panel that comes with such applications.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRaju VishwasView Question on Stackoverflow
Solution 1 - PhpDieterView Answer on Stackoverflow
Solution 2 - PhpArunView Answer on Stackoverflow
Solution 3 - PhpSanaullaView Answer on Stackoverflow
Solution 4 - Phpalbus_severusView Answer on Stackoverflow
Solution 5 - PhpEvanView Answer on Stackoverflow
Solution 6 - PhpÇağdaş KarademirView Answer on Stackoverflow
Solution 7 - PhpHiren ParghiView Answer on Stackoverflow
Solution 8 - PhpSamson 'Melah' NyabangaView Answer on Stackoverflow
Solution 9 - PhpNafas SaitView Answer on Stackoverflow
Solution 10 - PhpTai HoView Answer on Stackoverflow
Solution 11 - PhpSaqib AshrafView Answer on Stackoverflow