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

Nginx: disconnect when client sends chunked body exceeding desired size

· 52CE 我爱测

In nginx there is the following directive client_max_body_size : Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured va…

问题原文

原帖链接 · user3175580 · CC BY-SA 3.0

In nginx there is the following directive client_max_body_size:

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.

As it says, this is used when Content-Length is provided in the request. I am using nginx as reverse proxy. Unfortunately, my nodejs implementation for a particular URI requires a POST body to be provided with Transfer-Encoding: chunked -- it breaks otherwise. I still need to limit the accepted body size to prevent DoS. I'd like nginx to close the connection if too many bytes have been sent in the body.

Does nginx have that functionality? Or would I be better off implementing that on the nodejs server?

已采纳解答

原帖链接 · user3175580 · CC BY-SA 3.0

Fortunately, client_max_body_size actually does apply to Transfer-Encoding: chunked requests. I found this out during testing. The documentation just doesn't mention this.

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

资料来源与适用范围

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

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

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