Introduction
If a large number of server names are defined, or unusually long server names are defined, tuning the server_names_hash_max_size and server_names_hash_bucket_size directives at the http level may become necessary. The default value of the server_names_hash_bucket_size directive may be equal to 32, or 64, or another value, depending on CPU cache line size. If the default value is 32 and the server name is defined as “too.long.server.name.example.org
” then Nginx will fail to start and display the error message:
could not build the server_names_hash,
you should increase server_names_hash_bucket_size: 32
More information about this is found in the Nginx documentation here
Procedure
To modify this at the HTTP level on a cPanel server, you will need to modify the configuration file that contains this value, the location of this file on default instances is the following.
/etc/nginx/conf.d/ea-nginx.conf
By default, the values of these are below.
/etc/nginx/conf.d]cPs# grep 'server_names' ea-nginx.conf
server_names_hash_max_size 1024;
server_names_hash_bucket_size 128;
It's recommended to increase these by a multiple of 2, so if you were to increase the server_names_has_bucket_size from 128, you would increase this to 256.
Cent7 test: grep 'server_names' /etc/nginx/conf.d/ea-nginx.conf
server_names_hash_max_size 1024;
server_names_hash_bucket_size 256;
Once this is done, this value will also need to be increased in the /etc/nginx/ea-nginx/settings.json file to match the modification you made in /etc/nginx/conf.d/ea-nginx.conf.
Cent7 test: cat /etc/nginx/ea-nginx/settings.json
{"server_names_hash_max_size": 1024, "apache_port_ip": "127.0.0.1", "apache_port": "81", "apache_ssl_port": "444", "server_names_hash_bucket_size": 256, "apache_ssl_port_ip": "127.0.0.1"}
After doing this you can use nginx -t to check the Nginx syntax.
Cent7 test: nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
After you verify the syntax is correct, you can restart the service with the /scripts/restartsrv_nginx script.
Cent7 test: /scripts/restartsrv_nginx
Waiting for “nginx” to restart gracefully …waiting for “nginx” to initialize ………finished.
Service Status
nginx (nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf) is running as root with PID 193708 (systemd+/proc check method).
Startup Log
Jul 03 00:42:29 new-host.cprapid.com systemd[1]: Reloading nginx - high performance web server.
Jul 03 00:42:29 new-host.cprapid.com systemd[1]: Reloaded nginx - high performance web server.
Jul 04 00:42:25 new-host.cprapid.com systemd[1]: Reloading nginx - high performance web server.
Jul 04 00:42:26 new-host.cprapid.com systemd[1]: Reloaded nginx - high performance web server.
Jul 05 00:41:34 new-host.cprapid.com systemd[1]: Reloading nginx - high performance web server.
Jul 05 00:41:34 new-host.cprapid.com systemd[1]: Reloaded nginx - high performance web server.
Jul 06 00:41:33 new-host.cprapid.com systemd[1]: Reloading nginx - high performance web server.
Jul 06 00:41:33 new-host.cprapid.com systemd[1]: Reloaded nginx - high performance web server.
Jul 06 18:54:31 new-host.cprapid.com systemd[1]: Reloading nginx - high performance web server.
Jul 06 18:54:31 new-host.cprapid.com systemd[1]: Reloaded nginx - high performance web server.
nginx restarted successfully.