nginx - client request body is buffered to a temporary file
I get the following error in my log files every time I try to upload a large file.
a client request body is buffered to a temporary file /var/lib/nginx/body/0000000001
Although the file uploads successfully, I always get the above error.
I increased the client_body_buffer_size
to 1000m
which is what I expect the largest file uploaded to be. However, this is was just a guess and although I don't get that error anymore I am wondering if this is an appropriate value to set for the client_body_buffer_size
?
I would appreciate it if anyone can shed some light on this directive and how it should be used.
This is a warning, not an error. That's why it was prefaced with [warn]
in the log.
It means that the size of the uploaded file was larger than the in-memory buffer reserved for uploads.
The directive client_body_buffer_size
controls the size of that buffer.
If you can afford to have 1GB of RAM always reserved for the occasional file upload, then that's fine. It's a performance optimization to buffer the upload in RAM rather than in a temporary file on disk, though with such large uploads a couple of extra seconds probably doesn't matter much. If most of your uploads are small, then it's probably a waste.
In the end, only you can really make the decision as to what the appropriate size is.
If you don't want to NginX store the body content in a temporary file, you can set your config. like this:
client_body_buffer_size 10M;
client_max_body_size 10M;
If you set both of this configurations at the same max. size (in k, M or G for kB, MB or GB, respectively), you will prevent that NginX creates a temp. file.
For more info: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size and http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size