Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum recommended client_max_body_size value on Nginx

Tags:

nginx

server

What is the maximum recommended value of client_max_body_size on Nginx for upload of large files?

The web app that I'm working right now will expect uploads of max 100mb. Should I set client_max_body_size to something like 150mb to upload in a single request or do the slice strategy and send chunks of 1mb to the server keeping the client_max_body_size low?

like image 486
Drico Avatar asked Dec 10 '22 06:12

Drico


1 Answers

This is a subjective thing and use-case dependent. So the question you should ask yourself is What is the max size beyond which you don't want to allow an upload then use that.

Next what mistake people make is that they just set

client_max_body_size 150M;

In the nginx config in the server block. This is actually wrong because you don't want to allow people to be able to upload 150M of data to everyone and to every url. You will have a specific url for which you want the upload to be allowed. So you should have location like below

location /upload/largefileupload {
   client_max_body_size 150M;
}

And for rest urls you can keep it to as low as 2MB. This way you will be less susceptible to a generic ddos attack (large body upload attack). See below url

https://www.tomaz.me/2013/09/15/avoiding-ddos-attacks-caused-by-large-http-request-bodies-by-enforcing-a-hard-limit-in-your-web-server.html

like image 190
Tarun Lalwani Avatar answered Jan 24 '23 13:01

Tarun Lalwani