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

- **ID:** `nginx/name-too-long-buffer-overflow`
- **领域:** nginx
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| nginx/1.18.0 | active | — | — |
| nginx/1.20.0 | active | — | — |
| nginx/1.24.0 | active | — | — |
| nginx/1.26.0 | active | — | — |

## 解决方案

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）以减少名称长度。
   ```

## 无效尝试

- **** — 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. (70% 失败率)
- **** — The error is configuration-specific; removing names only avoids the symptom, not the root cause, and names must be re-added eventually. (50% 失败率)
- **** — 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. (60% 失败率)
