253

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 Commented Jun 19, 2014 at 12:14
  • 2
    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 Commented 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 Commented Jun 19, 2014 at 12:22
  • have you tried a ps aux | grep nginx to see if it is running? Commented 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. Commented Aug 26, 2016 at 15:22

16 Answers 16

424

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! You can test the nginx config by:

sudo nginx -t

Then you need to restart or reload nginx:

sudo nginx -s reload

OR

sudo systemctl restart nginx
Sign up to request clarification or add additional context in comments.

7 Comments

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/…
It's asking for a password to change the file. But I don't remember setting one. Am i missing something?
The path for nano should be nano /etc/nginx/nginx.conf .
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.
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.
|
61

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

Hi Arun, the issue with our server is, I am unable to find nginx installed but its still gives nginx error
find nginx inside /opt or /etc. Inside nginx find conf folder then nginx.conf.
If above idea dont work, then search for nginx.conf inside whole Linux, by any search tool.
` max_input_time = 24000`, 24000 is in milliseconds?
@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
41

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 Comment

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!
28
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 

Comments

20

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

Comments

11

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

Comments

9

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

Comments

9

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)

    2 Comments

    Very helpful about which serivce is causing the problem. Helped a lot
    I got 413 Payload Too Large from Nginx that could be fixed by client_max_body_size.
    7

    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.

    Comments

    3

    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
    

    Comments

    3

    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

    Comments

    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
    

    Comments

    2

    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 :)

    Comments

    1

    For anyone who comes across this issue when running WordPress over docker, the setup is a bit different because we do not have a php.ini file, and here is how you can fix it:

    1. Exec into your container (running WordPress) and copy the contents of your .htaccess file with:
     docker compose exec wordpress bash
    

    or if you are running the pure docker container:

      docker exec -it <container_name/ID> bash
    
    1. create the file in your host in the same location from where you are running your docker-compose or you can map the path for more convenience. Add the copied values from your container and include these lines:
      post_max_size = 20M  
      upload_max_filesize = 10M
    

    you should have a final file like this:

    # BEGIN WordPress
    php_value upload_max_filesize 512M
    php_value post_max_size 1024M
    
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress
    

    Next, mount this file .htaccess mapping it with the location of the original.

    here is my docker-compose example for a production-ready wordpress setup.

    services:
      wordpress:
        image: wordpress:latest
        container_name: container_name
        ports:
          - "8003:80"
        environment:
          WORDPRESS_DB_HOST: WORDPRESS_DB_HOST:PORT
          WORDPRESS_DB_NAME: WORDPRESS_DB_NAME
          WORDPRESS_DB_USER: WORDPRESS_DB_USER
          WORDPRESS_DB_PASSWORD: WORDPRESS_DB_PASSWORD
          WORDPRESS_AUTH_KEY: 'WORDPRESS_AUTH_KEY'
          WORDPRESS_SECURE_AUTH_KEY: 'WORDPRESS_SECURE_AUTH_KEY'
          WORDPRESS_LOGGED_IN_KEY: 'WORDPRESS_LOGGED_IN_KEY'
          WORDPRESS_NONCE_KEY: 'WORDPRESS_NONCE_KEY'
          WORDPRESS_AUTH_SALT: 'WORDPRESS_AUTH_SALT'
          WORDPRESS_SECURE_AUTH_SALT: 'WORDPRESS_SECURE_AUTH_SALT'
          WORDPRESS_LOGGED_IN_SALT: 'WORDPRESS_LOGGED_IN_SALT'
          WORDPRESS_NONCE_SALT: 'WORDPRESS_NONCE_SALT'
          WORDPRESS_TABLE_PREFIX: wp_
          WORDPRESS_DEBUG: 1
          WP_HOME: https://WP_HOME.com
        volumes:
          - wordpress_data:/var/www/html
          - ./wp-config.php:/var/www/html/wp-config.php
          - /.htaccess:/var/www/html/.htaccess
        restart: unless-stopped
    volumes:
      wordpress_data:
    
    

    for nginx:

    location / {
        proxy_pass http://your_host_name:your_port;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
        client_max_body_size 24000M;
        server_tokens off;
    }
    

    This should help things out and get you started quickly.

    Comments

    0

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

    Comments

    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.

    Comments

    Your Answer

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

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.