197

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

5
  • please look this links maybe help you cyberciti.biz/faq/… rtcamp.com/tutorials/php/increase-file-upload-size-limit
    – Ashouri
    Jun 19, 2014 at 12:14
  • 1
    Hi Mohammad, I have looked for nginx but I couldnt find it on my server. I am sure, nginx isnt installed on my server, so I am confused of why I am receiving an error message which belongs to Nginx Jun 19, 2014 at 12:20
  • first you mustbe sure ngix not installed on your server,but if you completely sure ,its maybe for security reason some server managers for confuse hackers use this trick
    – Ashouri
    Jun 19, 2014 at 12:22
  • have you tried a ps aux | grep nginx to see if it is running?
    – rpkamp
    Jun 19, 2014 at 18:33
  • Have you tried which nginx? That will give you the location of the executable, not the config file, but it should at least confirm whether or not nginx is installed. Aug 26, 2016 at 15:22

15 Answers 15

308

Source: cybercity

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;

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

Also do not forget to restart nginx:

systemctl restart nginx
5
  • 2
    When I do this my 413 turns into a 404. I'm using Amazon Linux on EC2. Also the nginx doc show a lowercase 'm'. nginx.org/en/docs/http/…
    – nu everest
    Dec 27, 2016 at 22:51
  • It's asking for a password to change the file. But I don't remember setting one. Am i missing something?
    – Sooraj
    Jun 17, 2017 at 18:36
  • 1
    The path for nano should be nano /etc/nginx/nginx.conf .
    – MaXi32
    Feb 27, 2018 at 7:19
  • 1
    Worked for me but NOTE: If your config already has a http { } section, add the rest inside of it! Adding a new http {} section will fail and give a "http" directive is duplicate error in the Nginx log.
    – jerclarke
    Mar 22, 2019 at 23:12
  • I've edited the answer to make it clear that you can add the client_max_body_size directive either in the http, server or location section, not only in the http section. See the docs. May 9, 2022 at 18:32
54

-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

5
  • Hi Arun, the issue with our server is, I am unable to find nginx installed but its still gives nginx error Nov 25, 2014 at 15:08
  • find nginx inside /opt or /etc. Inside nginx find conf folder then nginx.conf.
    – Arun
    Nov 26, 2014 at 4:58
  • If above idea dont work, then search for nginx.conf inside whole Linux, by any search tool.
    – Arun
    Nov 26, 2014 at 5:00
  • ` max_input_time = 24000`, 24000 is in milliseconds? Jul 22, 2020 at 7:39
  • 1
    @RishabhAgrahari Seconds! This sets the maximum time in seconds. The default setting is -1, which means that max_execution_time is used instead. Set to 0 to allow unlimited time
    – Sean
    Jul 23, 2020 at 20:53
34

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
1
  • 1
    I opened my nginx.conf file as instructed, but it was empty! I wasn't expecting that, but when I added your code it still worked...as I guess one would expect, but for some reason I wasn't and I was very happy when it did!
    – Andrew Fox
    Mar 26, 2019 at 4:40
26
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 
16

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
8

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
8

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;
}
  1. Finally restarted Nginx with the below command.

systemctl restart nginx

6

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.

3

First of all you need to pay attention to the response status code:

  • If it says "413 Content Too Large" it is returned by php itself (php.ini file)
  • If it says "413 Request Entity Too Large", then it is returned by nginx (if you use one).
  • If it says "403 Forbidden" (if you have Modsecurity installed), then most likely it is returned by Modsecurity.

  • If it is returned by php, then you'll need to change:
  • "post_max_size"(applies for all the files sent inside the request)
  • "upload_max_filesize" (applies for an individual file separately)

  • In either
  • "/etc/php/8.2/fpm/php.ini"
  • Or
  • "/etc/php/8.2/cli/php.ini" (Nginx servers usually work with fpm).

  • If it is returned by nginx, then you need to add "client_max_body_size 22M;" directive to the .conf file of your website.
    If it is returned by Modsecurity, then you need to change "SecRequestBodyLimit" directive in /etc/nginx/modsec/modsecurity.conf file to something like "SecRequestBodyLimit 23068672" (It is written in bytes)
    1
    • Very helpful about which serivce is causing the problem. Helped a lot
      – srokatonie
      Oct 13, 2023 at 10:51
    2

    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
    
    2

    Anyone looking for a solution for Apache2 (Ubuntu 18 for me), you can edit:

    /etc/apache2/apache2.conf
    

    And find/edit the line:

    LimitRequestBody 7000000 #7mb
    
    1

    Just open this file and ---

    sudo vim  /etc/nginx/nginx.conf
    

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

    client_max_body_size 100M;
    

    Then check nginx is okey or not by the following command

    sudo nginx -t
    

    If everything looks fine then you will get

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    

    Then restart nginx

    sudo systemctl restart nginx
    

    I hope your purpose is served :)

    1

    In my case, I was using nginx along with letsencrypt to put a ssl layer in front of my spring boot application.

    Putting clint_max_body_size property in "/etc/nginx/nginx.conf" did not work for me. Instead, I put this property inside the site specific conf file.

    sudo nano /etc/nginx/sites-available/mywebsite.com

    server {
        ...
        client_max_body_size 3M;
        ...
    }
    

    Post saving the above, restarted the nginx server and it worked !

    sudo service nginx stop

    sudo service nginx start

    0

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

    0

    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.

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.