Tuesday, June 4, 2013

Nginx Error - 413 Request Entity Too Large

nginx version: nginx/1.1.19, OS: Ubuntu12.04
Default nginx accepted body size limitation is 1MB.
You can add client_max_body_size in nginx.conf.
This parameter can put in http, server and location sections of configutation file.

Enlarge body size to 10MB

client_max_body_size 10M  

Or just disable it

client_max_body_size 0  

For example enlarge body size to 10MB
Add to http section:

$ sudo vi /etc/nginx/nginx.conf  
http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        client_max_body_size 10M;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
...
}

Or modify server and location section

$ sudo vi /etc/nginx/sites-available/default  
server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6
        client_max_body_size 10M;
        root /usr/share/nginx/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
                client_max_body_size 0;
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }
....
}  

Reload configuration:

$ sudo service nginx reload  

Done!

1 comment:

  1. Thank you for your post. I'm using nginx 1.1.19 and editing nginx.conf didnt work for me because in this version of nginx, using client_max_body_size in the HTTP context is ignored. I tried searching until I found this that I had to change it from /sites-available/default file though `default` file is not a .conf type file, thats why I didn't look for it first.

    ReplyDelete