Increase maximum upload size with nginx and PHP

Jacob Allred
#web-dev

I recently reconfigured my servers and switched from Apache HTTP to nginx. My wife wanted to upload some photos to her blog but it kept giving her an error. I checked the error log on the server and found this weird error message:

2014/12/23 16:03:18 [error] 23573#0: *4374978 client intended to send too large body: 1070520 bytes, client: 24.243.18.61, server: www.awkwardsheturtle.com, request: “POST /wp-admin/async-upload.php HTTP/1.1”, host: “www.awkwardsheturtle.com”, referrer: “http://www.awkwardsheturtle.com/wp-admin/media-new.php”

nginx

First I needed to increase the client maximum body size in nginx. This is done by adding the following line to /etc/nginx/nginx.conf in the http block:

client_max_body_size 8M;

Reload the nginx config and you should be good to go:

service nginx reload

PHP

Next, edit your php.ini (for me this is located at /etc/php5/fpm/php.ini). Find the following lines and update their values:

upload_max_filesize = 8M
post_max_size = 8M

Restart PHP to load the new configuration:

service php5-fpm restart