When configuring nginx, what considerations affect client_body_buffer_size?

I've set it to 10m for a website where users upload photos and image-memes (kind of like 9gag). Note that client_max_body_size is set to 10m as well. Overall, my reasoning is that the webserver should accept POST requests with images as big as 10MB (website policy) - and thus both these directives ought to be 10m.

Is this reasoning correct?

Can someone shed light on the factors affecting what values to set for client_body_buffer_size, and typical values of client_body_buffer_size (for the sort of web application I described)?

In case it matters, I utilize nginx as a reverse proxy.

1 Answer 1


The documentation states what client_body_buffer_size does:

Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. This is 8K on x86, other 32-bit platforms, and x86-64. It is usually 16K on other 64-bit platforms.

This memory is in use only while a request is being uploaded; once it is passed on to the backend, the memory is freed again. If a request is larger than this value, it will go to a temporary file and a warning will appear in the error log.

This means that you must have enough RAM to store any simultaneous uploads, or your server will begin swapping.

The performance impact of this is probably not that great, unless you are severely memory constrained and getting lots of uploads at the same time.

  • So would that mean client_body_buffer_size is dictated by the upper limit of the upload file sizes my application would accept? Feb 4, 2019 at 16:45
  • 1
    It doesn't make any sense to have a buffer size larger than the upload size you can accept. You could configure it, but it would not have any effect. Feb 4, 2019 at 16:46
  • Yep, makes sense. What confuses me is that most examples I see cite client_body_buffer_size size at 10k, whereas client_max_body_size is set to 8m. What kind of scenarios are those? Shouldn't buffer size always be as big as body size? Feb 4, 2019 at 18:04
  • 1
    @HassanBaig The typical request body is a form submission of perhaps a few hundred bytes at most. Image uploading is not a common operation for most web sites. If you only get three or four uploads per day it doesn't matter much whether it's going to RAM or a temporary file. Feb 4, 2019 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.