今天在给nginx添加几十个域名后,重启nginx的时候,报错”[emerg]: could not build the server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 128″
在nginx.conf配置文件的http{}把server_names_hash_bucket_size 128改为server_names_hash_bucket_size 512,按32的倍数往上加,再重启问题解决。
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
[emerg]: could not build the server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 128
configuration file /usr/local/nginx/conf/nginx.conf test failed
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
最后查了下资料:
保存服务器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果 hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键值。因此,如果Nginx给出需要增大 hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.