DEBUG.WIKI
丽萨主机;为跨境业务选好 IP;原生 / 住宅 IP · 按套餐选择;查看 IP →
OnlineSIM:在线接收短信,虚拟号码租用
野草云;香港 200Mbps 峰值;不限月流量 · BGP VPS;查看套餐 →

解决 Nginx 启动警告 could not build optimal types_hash

分析 Nginx 包含过多 MIME 类型报 types_hash 警告诱因,详解 types_hash_max_size 参数调优。

问题现象

执行 nginx -t 测试配置时控制台打印警告:

nginx: [warn] could not build optimal types_hash, you should increase 
either types_hash_max_size: 1024 or types_hash_bucket_size: 64; 
ignoring types_hash_bucket_size

触发根因

Nginx 在内存中构建 MIME 类型哈希表时,由于引入了庞大的 mime.types 扩展定义,预分配的哈希桶容量不够。

解决方案

在 nginx.conf 的 http 块中调大哈希参数:

http {
    types_hash_max_size 4096;
    types_hash_bucket_size 128;
}

验证方法

再次测试语法:sudo nginx -t,警告彻底消失。