I'm running nginx as a frond end to php based Apache+mod_fastcgi server. My app lets user upload images upto 2MB in size. When users trying to upload 1.5MB+ size image file using nginx reverse proxy, they are getting the following error on screen:
Nginx 413 Request Entity Too Large
How do I fix this problem and allow image upload upto 2MB in size?
The client_max_body_size directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error "Request Entity Too Large" (413). To fix this issue edit your nginx.conf, enter:
# vi /usr/local/nginx/conf/nginx.conf
Add the following to increase the size limit in nginx.conf, enter:
client_max_body_size 2M;
Save and close the file. Reload the nginx webserver, enter:
# /usr/local/nginx/sbin/nginx -s reload
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 8 comments… read them below or add one }
when i use
client_max_body_size 2MB;
there is something wrong:
nginx: [emerg] “client_max_body_size” directive invalid value in conf/nginx.conf
maybe you should use 2m not 2mb
my nginx version:
nginx: nginx version: nginx/1.0.5
Its not 2MB its 2m, see:
http://wiki.nginx.org/HttpCoreModule#client_max_body_size
it should be:
client_max_body_size 2M;
Thanks for the heads up!
Thanks, man! Solved my problem!
Thanks a lot!!!
Thanks for this!
Something to note: I had `client_max_body_size` being set in a variety of files in the nginx directory. To quickly see if it is being set (and therefore causing overrides or conflicts) you can use the following line in the nginx directory.
sudo grep -R ‘client_max_body_size’ ./*
Thanks,
Josh
@nixCraft
I would be happy to receive that kind of error (Nginx 413 Request Entity Too Large).
Unfortunately, my browser (Firefox 20) shows me a page with the message “This page contains no data” when someone tries to upload a file more client_max_body_size
I have tried to create a custom page 413 and get’s invoked when client_max_body_size get exceeded to no avail.