nginx resource_error ai_generated true

“limit_conn_zone”中的 1024 个区域不够

nginx: [emerg] 1024 zones are not enough in "limit_conn_zone"

ID: nginx/limit-conn-zone-too-small

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2024-07-18首次发现

版本兼容性

版本状态引入弃用备注
nginx/1.18.0 active
nginx/1.20.0 active
nginx/1.24.0 active
nginx/1.26.0 active

根因分析

limit_conn_zone 指令为每个键分配了固定数量的插槽(默认 1024),在高并发下会耗尽。

English

The limit_conn_zone directive allocates a fixed number of slots (default 1024) for tracking connections per key, which is exhausted under high concurrency.

generic

官方文档

https://nginx.org/en/docs/http/ngx_http_limit_conn_module.html#limit_conn_zone

解决方案

  1. 增加 limit_conn_zone 指令中的区域大小:`limit_conn_zone $binary_remote_addr zone=addr:10m;`(默认是 1m,可容纳约 1024 个区域)
  2. 如果使用多个键,为每个键创建单独的区域以分散负载:`limit_conn_zone $server_name zone=server:5m; limit_conn_zone $binary_remote_addr zone=addr:5m;`
  3. 使用状态模块监控区域使用情况并动态调整:在 location 中添加 `stub_status;` 并检查活跃连接以估算所需的区域大小。

无效尝试

常见但无效的做法:

  1. 80% 失败

    limit_conn controls the maximum number of connections per key, not the number of zones/slots available for tracking.

  2. 30% 失败

    This eliminates the error but also removes the intended connection limiting functionality, potentially leading to resource exhaustion.

  3. 50% 失败

    Large zones consume significant memory; if the system runs out of memory, nginx may crash or fail to start.