Nginx: 413 Request Entity Too Large Error and Solution

by on July 12, 2011 · 8 comments· LAST UPDATED January 4, 2012

in

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



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 8 comments… read them below or add one }

1 lowry.shaw August 31, 2011 at 6:34 am

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

Reply

2 Lukasz November 3, 2011 at 10:40 pm
3 grissom January 4, 2012 at 3:02 pm

it should be:
client_max_body_size 2M;

Reply

4 Vivek Gite January 4, 2012 at 6:58 pm

Thanks for the heads up!

Reply

5 Jan August 21, 2012 at 12:24 pm

Thanks, man! Solved my problem!

Reply

6 Morten November 29, 2012 at 5:39 pm

Thanks a lot!!!

Reply

7 Joshua Pinter December 7, 2012 at 5:37 pm

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

Reply

8 Nick_K May 10, 2013 at 10:22 am

@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.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: