【Nginx】「[emerg]: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32」というエラーが出た場合の対処法

Nginxを起動しようとすると以下のエラーが出た。

$ sudo /etc/init.d/nginx start

[emerg]: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
configuration file /etc/nginx/nginx.conf test failed

長いサーバ名を定義している場合に発生するようです。

解決方法

# /etc/nginx/nginx.conf

http {
  server_names_hash_bucket_size 64;
}

参考

http://nginx.org/ja/docs/http/server_names.html