How To Increase File Upload Size in NGINX

Last updated on August 10th, 2020 at 03:05 am

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

Bonus Read : How to Hide NGINX Server Version & Name

 

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;
   ...
}

Bonus Read : How to Setup NGINX Load Balancer

 

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;
}

Bonus Read : How to Redirect Subfolder to Subdomain in NGINX

 

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! Hopefully the above tutorial will help you increase file upload size limit in NGINX.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!