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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With