How To Increase File Upload Size in NGINX

By FeRuM • April 13, 2023

By default, NGINX supports max file upload size of 1 Mb. If users upload bigger files, they will get a “413: Request Entity Too Large” error. Here’s how to increase file upload size in NGINX to fix this issue.

 

How To Increase File Upload Size in NGINX

Here are the step to increase file upload size in NGINX. We will use the client_max_body_size directive to set the NGINX max file upload size limit. You can place client_max_body_size directive in http, server or location.

 

1. Open NGINX configuration file

Open terminal and run the following command to open NGINX configuration file in a text editor.

$ sudo /etc/nginx/nginx.conf

 

2. Increase File Upload Size in NGINX

Let’s say you want to increase file upload size to 50MB across your entire site. So add the line client_max_body_size 50M to http block. Here’s an example,

		http {
			...
			client_max_body_size 50M;
			...
		}
	

 

Let’s say you want to increase file size upload limit only for HTTPS requests but not HTTP requests. In that case, the line client_max_body_size 50M to server block that listens to HTTPS port 443 but not the server block that listens to port 80.

		server {
			listen 80;
			...
			}
			server{
			listen 443;
			...
		}
	

You can also use the above approach, if you want to increase file upload size only for a specific website/domain/subdomain/app.

 

Let’s say you want to increase upload file size limit for a particular directive/URL. In that case, you can add the line client_max_body_size 100M. Let’s say you want to increase file upload size for /uploads folder

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

 

3. Restart NGINX

Finally, run the following command to check syntax of your updated config file.

$ sudo nginx -t
	

 

If there are no errors, run the following command to restart NGINX server.

		$ sudo service nginx reload #debian/ubuntu
		$ systemctl restart nginx #redhat/centos
	

 

That’s it! Now you know how to increase file upload size limit in NGINX.