413 Request Entity Too Large - File Upload Issue

后端 未结 10 1269
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 10:28

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. <
相关标签:
10条回答
  • 2020-12-04 11:07

    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
    
    0 讨论(0)
  • 2020-12-04 11:12

    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
    
    0 讨论(0)
  • 2020-12-04 11:13
    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 
    
    0 讨论(0)
  • 2020-12-04 11:13

    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
    
    0 讨论(0)
  • 2020-12-04 11:17

    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
    
    0 讨论(0)
  • 2020-12-04 11:20

    -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

    0 讨论(0)
提交回复
热议问题