fix nginx increase server_names_hash_bucket_size error

When adding new virtual hosts in your nginx configuration file, you can experience this error message:

1
2
3
# nginx -t
2008/11/13 09:37:03 [emerg] 12299#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
2008/11/13 09:37:03 [emerg] 12299#0: the configuration file /etc/nginx/nginx.conf test failed

_server_names_hash_bucket_size_ controls the maximum length of a virtual host entry (ie the length of the domain name).

In other words, if your domain names are long, increase this parameter.

You need to add this flag in the _http_ context:

1
2
3
4
http {
server_names_hash_bucket_size 64;
...
}

After increasing the value, test your configuration file and reload nginx:

1
2
3
4
# nginx -t
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf was tested successfully
# kill -HUP ` /var/run/nginx.pid`