今天遇到這個錯誤,現記錄下解決方案:
在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的值。