今天在給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的倍數往上加,再重新開機問題解決。
[root@localhost 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
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的提示,那麼首要的是增大前一個參數的大小.
<b>本文轉自 freeterman 51CTO部落格,原文連結:http://blog.51cto.com/myunix/1622277,如需轉載請自行聯系原作者</b>