【记录】Nginx错误could not build the server_names_hash you should increase server_names_hash_bucket_size: 32

今天遇到这个错误,现记录下解决方案:

在nginx的配置文件的http段中增加如下配置:

server_names_hash_bucket_size 64;

下面是nginx官方文档解释:

如果定义了大量名字,或者定义了非常长的名字,那可能需要在http配置块中使用server_names_hash_max_size和server_names_hash_bucket_size指令进行调整。server_names_hash_bucket_size的默认值可能是32,或者是64,或者是其他值,取决于CPU的缓存行的长度。如果这个值是32,那么定义“too.long.server.name.example.org”作为虚拟主机名就会失败,而nginx显示下面错误信息:
could not build the server_names_hash,
you should increase server_names_hash_bucket_size: 32
出现了这种情况,那就需要将指令的值扩大一倍:

http {
    server_names_hash_bucket_size  64;
    ...
如果定义了大量名字,得到了另外一个错误:

could not build the server_names_hash,
you should increase either server_names_hash_max_size: 512
or server_names_hash_bucket_size: 32
那么应该先尝试设置server_names_hash_max_size的值差不多等于名字列表的名字总量。如果还不能解决问题,或者服务器启动非常缓慢,再尝试提高server_names_hash_bucket_size的值。

  

猜你喜欢

转载自www.cnblogs.com/wbl001/p/11436444.html