EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Nginx Tutorial Nginx Max Upload Size
Secondary Sidebar
Nginx Tutorial
  • Basic
    • Nginx Add_header
    • Nginx FastCGI
    • Nginx WAF
    • Nginx Forward Proxy
    • Nginx Ingress Annotations
    • Nginx Location Directive
    • Nginx User
    • Nginx Port
    • Nginx Auth_request
    • Nginx Autoindex
    • Nginx if else
    • Nginx uWSGI
    • Nginx X-Forwarded-For
    • Nginx GUI
    • NGINX Unit
    • NGINX if
    • Nginx default_server
    • Nginx worker_connections
    • Nginx Authentication
    • Nginx Gateway Timeout
    • Nginx Error_page
    • Nginx Server Block
    • Nginx Forbidden
    • Nginx Modules
    • Nginx Max Upload Size
    • Nginx vs LiteSpeed
    • Nginx multiple server_name

Nginx Max Upload Size

Introduction to Nginx Max Upload Size

Nginx max upload size is defined as how much big size of files we can upload by using nginx. The nginx default file upload size limit is 1 MB; if suppose the user uploads a file which is more than 1 MB, then the user will get the 413 error, i.e., entity request is too large. We can increase the max size of the upload limit in nginx by using the directive of client_max_body_size.

Nginx Max Upload Size

Overview of Nginx Max Upload Size

Nginx will abort our connection when we upload the large files, which is the max limit we have defined in the nginx configuration files. We can change the nginx file-max upload size limit using the nginx configuration file. After configuring the max upload limit of the file, we need to restart the nginx server; without a restart, it will not work properly. The default limit of nginx file upload is too low; if suppose we want to upload images or video, then it will create an issue in the application and show an error to the user while uploading the file.

How to Increase Nginx Max Upload Size?

Below are the steps to increase the nginx max upload size. We will use the directive name client_max_body_size for setting the limit of max file upload. We can place the directive of client_max_body_size in the server, http of location.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)

1. In the first step, we need to install the nginx server in our system. We can install the nginx server by using rpm, and source, as well as by using the binary installation.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Code:

apt-get install nginx

Output:

Nginx Max Upload Size 1

2. After installing the server of nginx, we need to start the nginx server by using the “service nginx start” command. After beginning the nginx service, we can check the status of the service. We have installed the nginx version as 1.18 as follows.

Code:

service nginx status
nginx –V

Output:

Nginx Max Upload Size 2

3. In this step, we create our website’s directory from which we use the auto indexes. We are creating the directory name as nginx_autoindex. After creating the directory, we provide the 755 umask value to the specified directory.

Code:

mkdir -p /nginx_maxupload
chmod -R 755 /nginx_maxupload

Output:

Nginx Max Upload Size 3

4. After creating the directory and providing the umask value to the same now, we are opening the nginx configuration file to add the configuration of the nginx autoindex as follows.

Nginx Max Upload Size 4

5. After opening the nginx configuration file in this step, we increase the file upload size limit of the nginx server. If suppose we want to increase the limit of our entire website to 25 MB, then we need to add the below code into the http block as follows.

Code:

http {
   client_max_body_size 50M;
}

Output:

Nginx Max Upload Size 5

6. If suppose we want to increase the limit of file size upload only for the specified https request but not for the request of HTTP, then we need to add the client_max_body_size 50 MB line into the block of https, which listen from the 443 but not in a block which was listening from 80.

Code:

server{
  listen 80;
}
server{
  listen 443;
  client_max_body_size 50M;
}

Output:

client_max_body_size 50 MB

7. We can also use the above approach suppose we want to increase the upload file size limit of a specific website or domain. If suppose we want to increase the file size directive for a specified URI or directive, in that case, we can use the client_max_body_size directive in the nginx_maxupload folder as follows.

Code:

location /nginx_maxupload {
  client_max_body_size 40M;
}

Output:

ncrease the file size directive

8. To take the effect of the above change, we need to restart the nginx server by using the following command. However, before that, we need to check that our configuration is valid in the nginx configuration file by using the following command.

Code:

nginx –t
service nginx restart

Output:

configuration is valid

How to Limit File Nginx Max Upload Size?

We can limit the file upload size in nginx; by limiting the file upload size, we can prevent DOS attacks and many other issues. The below steps show how we can limit the max upload size of the file. In the below example, we are limiting the upload size of the file of http, server, and directive as follows.

1. In the first step, we open the nginx configuration file using the vi command for editing purposes.

Nginx Max Upload Size 9

2. After opening the nginx configuration file in this step, we limit the file upload size of the nginx server to 100 MB of the http directive.

Code:

http {
   client_max_body_size 100M;
}

Output:

Nginx Max Upload Size 10

3. If suppose we want to limit the upload file size only for the specified https request but not for the request of HTTP, then we need to add the client_max_body_size 100M line into the block of HTTP, which listen from the 80 but not in a block which was listened from 443.

Code:

server{
  listen 443;
}
server{
  listen 80;
  client_max_body_size 100M;
}

Output:

Nginx Max Upload Size 11

4. If suppose we want to limit the upload file size directive for a specified URI or directive, in that case, we can use the client_max_body_size directive in the nginx_maxupload folder as follows.

Code:

location /nginx_maxupload {
  client_max_body_size 100M;
}

Output:

for specified URI or directive

5. After limiting the directive of client_max_body_size, we need to check the syntax of nginx configuration files. After checking the syntax, if suppose the syntax of the file is ok, then we need to restart the nginx server; if suppose syntax is not ok, then we need to verify the same.

Code:

nginx –t
service nginx restart

Output:

need to check the syntax

Conclusion

We can change the nginx file-max upload size limit using the nginx configuration file. The nginx default file upload size limit is 1 MB; if suppose the user uploads a file which is more than 1 MB, then the user will get the 413 error, i.e., entity request is too large.

Recommended Articles

This is a guide to Nginx Max Upload Size. Here we discuss the introduction and how to increase and limit file nginx max upload size. You may also have a look at the following articles to learn more –

  1. Nginx Add_header
  2. Nginx Location Directive
  3. Nginx WAF
  4. Nginx FastCGI
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more