Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default nginx client_max_body_size

Tags:

nginx

People also ask

What is the default client_max_body_size?

By default, Nginx has a limit of 1MB on file uploads. To set file upload size, you can use the client_max_body_size directive, which is part of Nginx's ngx_http_core_module module. This directive can be set in the http, server or location context.

What is default file in NGINX?

By default the file is named nginx. conf and for NGINX Plus is placed in the /etc/nginx directory. (For NGINX Open Source , the location depends on the package system used to install NGINX and the operating system. It is typically one of /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.)

What is client body buffer size?

http , server , location. Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. This is 8K on x86, other 32-bit platforms, and x86-64.

What is NGINX location?

Every NGINX configuration file will be found in the /etc/nginx/ directory, with the main configuration file located in /etc/nginx/nginx. conf . NGINX configuration options are known as “directives”: these are arranged into groups, known interchangeably as blocks or contexts .


The default value for client_max_body_size directive is 1 MiB.

It can be set in http, server and location context — as in the most cases, this directive in a nested block takes precedence over the same directive in the ancestors blocks.

Excerpt from the ngx_http_core_module documentation:

Syntax:   client_max_body_size size;
Default:  client_max_body_size 1m;
Context:  http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

Don't forget to reload configuration by nginx -s reload or service nginx reload commands prepending with sudo (if any).


Pooja Mane's answer worked for me, but I had to put the client_max_body_size variable inside of http section.

enter image description here


You can increase body size in nginx configuration file as

sudo nano /etc/nginx/nginx.conf

client_max_body_size 100M;

Restart nginx to apply the changes.

sudo service nginx restart


Nginx default value for client_max_body_size is 1MB

You can update this value by three different way

1. Set in http block which affects all server blocks (virtual hosts).

http {
    ...
    client_max_body_size 100M;
}

2. Set in server block, which affects a particular site/app.

server {
    ...
    client_max_body_size 100M;
}

3. Set in location block, which affects a particular directory (uploads) under a site/app.

location /uploads {
    ...
    client_max_body_size 100M;
}

For more info click here


You have to increase client_max_body_size in nginx.conf file. This is the basic step. But if your backend laravel then you have to do some changes in the php.ini file as well. It depends on your backend. Below I mentioned file location and condition name.

sudo vim /etc/nginx/nginx.conf.

After open the file adds this into HTTP section.

client_max_body_size 100M;