1
votes

i have nginx on centOS distro. Everything is configured to upload files fine for me..

  • in etc/php.ini (dont know why on centos this file is in root of etc but its working) i have upload_max_filesize 60M, client_max_body_size 80M and post_max_size 80M.

Other files like nginx server configuration have these upload directives too.

But when I'm uploading a 1mb file nginx is erroring 413 Request Entity Too Large. My web app is showing that server have 60mb file limit like info.php file. I did a reboot, nginx reload, restart, php reload.

I have checked everything on stackoverflow and net to fix this but nothing helped.

Nginx logs: Nginx is showing that user is trying to upload bigger file than limit.

There is a pdf of my info.php file: http://docdro.id/YAylJcO

2

2 Answers

2
votes

Have you edited your nginx.conf. Add client_max_body_size xxM inside the server section, where xx is the size (in megabytes) that you want to allow.

0
votes

By default, nginx is configured to allow a client maximum body size of 1MB. The files you are uploading (~8MB) are larger than 1MB, which is why the 413 (Request Entity Too Large) error is being returned.

To fix this issue, simply edit nginx.conf and add a client_max_body_size configuration like so:

    ######################
    # HTTP server
    ######################
    server {
        ...
        listen       80;
        server_name  xxxx.com;
        client_max_body_size 20M;
        ...
    }

If you have HTTPS configured as well, be sure to add client_max_body_size there as well:

    ######################
    # HTTPS server
    ######################
    server {
        ...
        listen       443 default_server ssl;
        server_name  xxxx.com;
        client_max_body_size 20M;
        ...
    }

reload your server and you should be good!

[server]$ sudo service nginx reload


More info on client_max_body_size here: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

Syntax: client_max_body_size size;

Default: client_max_body_size 1m;

Context: http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.