大网数据广告活动
服务器运维问答

Optimizing nginx client_body_buffer_size for web app accepting file uploads

· 52CE 我爱测

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. O…

问题原文

原帖链接 · Hassan Baig · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。