nginx keeps saying client intended to send too large body
. Googling and RTM pointed me to client_max_body_size
. I set it to 200m
in th
Someone correct me if this is bad, but I like to lock everything down as much as possible, and if you've only got one target for uploads (as it usually the case), then just target your changes to that one file. This works for me on the Ubuntu nginx-extras mainline 1.7+ package:
location = /upload.php {
client_max_body_size 102M;
fastcgi_param PHP_VALUE "upload_max_filesize=102M \n post_max_size=102M";
(...)
}
Following nginx documentation, you can set client_max_body_size 20m ( or any value you need ) in the following context:
context: http, server, location
I had a similar problem recently and found out, that client_max_body_size 0;
can solve such an issue. This will set client_max_body_size to no limit. But the best practice is to improve your code, so there is no need to increase this limit.
As of March 2016, I ran into this issue trying to POST json over https (from python requests, not that it matters).
The trick is to put "client_max_body_size 200M;" in at least two places http {}
and server {}
:
1. the http
directory
/etc/nginx/nginx.conf
2. the server
directory in your vhost.
/etc/nginx/sites-available/mysite.com
, for those who do not have vhosts, it's probably your nginx.conf or in the same directory as it.3. the location /
directory in the same place as 2.
/
, but if its not working at all, i'd recommend applying this to /
and then once its working be more specific.Remember - if you have SSL, that will require you to set the above for the SSL server
and location
too, wherever that may be (ideally the same as 2.). I found that if your client tries to upload on http, and you expect them to get 301'd to https, nginx will actually drop the connection before the redirect due to the file being too large for the http server, so it has to be in both.
Recent comments suggest that there is an issue with this on SSL with newer nginx versions, but i'm on 1.4.6 and everything is good :)
You need to apply following changes:
Update php.ini
(Find right ini file from phpinfo();
) and increase post_max_size
and upload_max_filesize
to size you want:
sed -i "s/post_max_size =.*/post_max_size = 200M/g" /etc/php5/fpm/php.ini
sed -i "s/upload_max_filesize =.*/upload_max_filesize = 200M/g" /etc/php5/fpm/php.ini```
Update NginX settings for your website and add client_max_body_size
value in your location
, http
, or server
context.
location / {
client_max_body_size 200m;
...
}
Restart NginX and PHP-FPM:
service nginx restart
service php5-fpm restart
NOTE: Sometime (In my case almost every time) you need to kill php-fpm
process if it didn't refresh by service command properly. To do that you can get list of processes (ps -elf | grep php-fpm
) and kill one by one (kill -9 12345
) or use following command to do it for you:
ps -elf | grep php-fpm | grep -v grep | awk '{ print $4 }' | xargs kill -9
If you are using windows version nginx, you can try to kill all nginx process and restart it to see. I encountered same issue In my environment, but resolved it with this solution.