nginx server error: 413 Request Entity Too Large

Monday, November 21, 2011 posted by Till

The nginx webserver has a max. body size limit of 1 MB for requests as default. This might be too low for file uploads in scripts and you will see the following error message when you try to upload a file:

 413 Request Entity Too Large

The configuration variable for this option is "client_max_body_size" and it can be set in the http, server and location sections of the nginx configuration file. To set the Limit globally to 25 MB, edit the nginx.conf file and add:

client_max_body_size 20M;

in the http section.

Example for Ubuntu Linux:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        geoip_country  /etc/nginx/geoip/GeoIP.dat; # the country IP database
        geoip_city     /etc/nginx/geoip/GeoLiteCity.dat; # the city IP database
        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        client_max_body_size 20M;

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

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

Be Sociable, Share!



2 Responses to “nginx server error: 413 Request Entity Too Large”

  1. gadelkareem says:

    Extended description of HttpLimitZoneModule and HttpLimitReqModule usage with examples and how to exclude a whitelist of IPs can be found here Limit Requests Per IP On Nginx Using HttpLimitZoneModule And HttpLimitReqModule Except Whitelist

  2. I would suggest looking at all the different places where `client_max_body_size` could be set. For example, in the server and location sections. Anywhere that Nginx is pulling configuration files from.

    To find any occurrences of `client_max_body_size`, try the following unix command from the nginx root directory:

    sudo grep -R ‘client_max_body_size’ ./*

Leave a Reply