Setting server_names_hash_max_size

You ever encountered a problem with nginx: [warn] could not build optimal server_names_hash? I have the solution.

The full error string is as

nginx: [warn] could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size

A solution is to check server_names_hash_max_size directive under http {}

sudo nano nginx.conf
http {
  # ..
  server_names_hash_bucket_size 64;
  # server_name_in_redirect off;
  server_names_hash_max_size 4112;
  # ..