[emerg] could not build server

    xiaoxiao2022-07-12  146

    解决nginx报错

    nginx: [emerg] could not build server_names_hash, you should increase server_nam es_hash_bucket_size: 32 nginx: configuration file xxxx/conf/nginx.conf test failed

    报错原因

    该报错产生的原因主要是因为Nginx中的server配置中server_name的定义值过长产生的。

    解决方法

    在Nginx的http字段内添加如下代码,放大默认bucket_size

    http { server_names_hash_bucket_size 64; ..... } 注意:如果已经存在该字段信息,需要加大后面的数值。且数值必须是32的倍数

    这时候可能有的同学要问了,他的默认值是多少。根据Nginx的官方文档分析,server_names_hash_bucket_size的默认值有可能是32也有可能是64,或者是其他值,这个默认值的大小取决于CPU的缓存行长度,如果这个值是32,那么定义的如下代码就会报错

    server { listen 80; server_name www.mslinux.zhongguolong.too.com; # >=32就会报错 } 如果域名数量=32报错就和文档中一致。此时就需要我们将指令值放大; http { server_names_hash_bucket_size 64; } 在执行nginx -t将会报错解决

    如果定义了一条特别长的server_name。报错如下面代码所示

    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的值。

    http { server_names_hash_max_size 【值为域名长度总和】; server_names_hash_bucket_size 【上升值】; }

    加油!!方法总比问题多!!

    最新回复(0)