nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size

This is most likely happening because of the long domain name. You can fix this by adding

server_names_hash_bucket_size  64;

at the top of your http block (probably located in /etc/nginx/nginx.conf). I quote from the nginx documentation what to do when this error appears: In this case, the directive value should be increased to the next power of two. So in your case it should become 64.

If you still get the same error, try increasing to 128 and further.

Reference: http://nginx.org/en/docs/http/server_names.html#optimization


  • open /etc/nginx/nginx.conf with write privileges
  • uncomment or add server_names_hash_bucket_size 64;
  • restart nginx sudo service nginx restart

If the error still persists:

  • increase server_names_hash_bucket_size in steps 128, 256, 512, and so on (increasing by a power of 2 each time). eg. server_names_hash_bucket_size 128;
  • restart the nginx each time until error is gone (error will always be the same no matter what value you already set)

This sounds perhaps a bit random, but it might help an nginx newb like myself.
I got this error when I left off a ; on the server_name line.

had:

server_name    www.mydomain.com  
access_log     /var/log/nginx/www.mydomain.com; 

fix:

server_name    www.mydomain.com;  
access_log     /var/log/nginx/www.mydomain.com; 

All directives in nginx config files must end with a ;
I often highlight ;s in my file before saving/uploading as a final check after editing.