nginx config_error ai_generated true

服务器名称哈希桶大小配置值过小

nginx: [emerg] the "server_names_hash_bucket_size" directive value is too small

ID: nginx/name-too-long-buffer-overflow

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

版本兼容性

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

根因分析

配置的 server_names_hash_bucket_size 不足以容纳定义的服务器名称长度,导致哈希表桶溢出。

English

The configured server_names_hash_bucket_size is insufficient for the length of server names defined, causing hash table bucket overflow.

generic

官方文档

https://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size

解决方案

  1. 在 http 块中将 server_names_hash_bucket_size 增加到至少 128:`http { server_names_hash_bucket_size 128; ... }`
  2. 如果错误仍然存在,将值加倍(例如 256)并重新加载:`http { server_names_hash_bucket_size 256; }`
  3. 缩短长服务器名称或使用通配符(例如 *.example.com 替代 very-long-subdomain.example.com)以减少名称长度。

无效尝试

常见但无效的做法:

  1. 70% 失败

    server_names_hash_max_size sets the total hash size, while bucket size controls per-bucket alignment; max_size without increasing bucket_size still causes overflow for long names.

  2. 50% 失败

    The error is configuration-specific; removing names only avoids the symptom, not the root cause, and names must be re-added eventually.

  3. 60% 失败

    The value must be a power of two (e.g., 32, 64, 128, 256) to align with CPU cache lines; non-power-of-two values are ignored or cause other errors.