nginx
resource_error
ai_generated
true
nginx:[警报] 1024 个工作连接不足以连接到上游
nginx: [alert] 1024 worker_connections are not enough while connecting to upstream
ID: nginx/worker-connections-are-not-enough-while-connecting-to-upstream
80%修复率
85%置信度
1证据数
2023-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| nginx 1.24.0 | active | — | — | — |
| nginx 1.22.1 | active | — | — | — |
| nginx 1.20.2 | active | — | — | — |
| nginx 1.18.0 | active | — | — | — |
根因分析
同时连接数超过了 worker_connections 限制,导致连接上游服务器失败。
English
The number of simultaneous connections exceeds the worker_connections limit, causing connection failures to upstream servers.
官方文档
https://nginx.org/en/docs/ngx_core_module.html#worker_connections解决方案
-
增加 worker_connections 并调整系统限制: events { worker_connections 4096; multi_accept on; } 同时增加系统最大打开文件数:ulimit -n 65536 并在 /etc/security/limits.conf 中设置: * soft nofile 65536 * hard nofile 65536 然后重新加载 nginx。 -
增加 worker_processes 数量以分配连接: worker_processes auto; 这将使用所有 CPU 核心;每个 worker 有自己的连接池。
-
实施速率限制或按 IP 限制连接以防止滥用: limit_conn_zone $binary_remote_addr zone=addr:10m; limit_conn addr 100; 这将限制每个客户端的连接数,以保持在 worker_connections 范围内。
无效尝试
常见但无效的做法:
-
50% 失败
System limits (ulimit -n, fs.file-max) may still cap the total connections; also the OS may have per-process limits.
-
40% 失败
While it reduces connection duration, it increases connection churn and may still hit the limit under high concurrency.
-
30% 失败
Multi_accept affects connection acceptance behavior but does not increase the maximum number of connections.