Error
: could not build the server_names_hash, you should increase server_names_hash_bucket_size .
Today I have migrated my site to new CentOS 7 powered with Nginx, php-fpm and WordPress. After doing minimal configuration , I tried to restart the Nginx service. But the nginx service failed to restart.
Given below is reference from our server
[root@server ~]# systemctl restart nginx Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details. [root@server ~]#
In above reference, you can see system has suggested to run the command journalctl -xn
.
After using command journalctl -xn
we got reason in more details. Given below is the detail –
[root@server nginx]# journalctl -xn
— Logs begin at Thu 2014-11-27 04:58:50 EST, end at Sat 2014-11-29 00:01:19 EST. —
Nov 29 00:01:01 sharadchhetri.com anacron[14989]: Normal exit (0 jobs run)
Nov 29 00:01:01 sharadchhetri.com run-parts(/etc/cron.hourly)[14991]: finished 0anacron
Nov 29 00:01:01 sharadchhetri.com run-parts(/etc/cron.hourly)[14993]: starting 0yum-hourly.cron
Nov 29 00:01:01 sharadchhetri.com run-parts(/etc/cron.hourly)[14997]: finished 0yum-hourly.cron
Nov 29 00:01:19 sharadchhetri.com systemd[1]: Starting The nginx HTTP and reverse proxy server…
— Subject: Unit nginx.service has begun with start-up
— Defined-By: systemd
— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
—
— Unit nginx.service has begun starting up.
Nov 29 00:01:19 sharadchhetri.com nginx[15001]: nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size
Nov 29 00:01:19 sharadchhetri.com nginx[15001]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 29 00:01:19 sharadchhetri.com systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 29 00:01:19 sharadchhetri.com systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
— Subject: Unit nginx.service has failed
— Defined-By: systemd
— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
—
— Unit nginx.service has failed.
—
— The result is failed.
Nov 29 00:01:19 sharadchhetri.com systemd[1]: Unit nginx.service entered failed state.
[root@server nginx]#
How To Solve
To solve this problem, add server_names_hash_bucket_size 64;
in nginx.conf file at http block.
http { .. server_names_hash_bucket_size 64; .. }
Check the nginx configuration by using below given command.
nginx -t
Here is our reference –
[root@server nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@server nginx]#
If all things are good, restart the nginx service.
On CentOS 7 / RHEL 7
systemctl restart nginx.service
On CentOS – 6/5 / RHEL – 6/5 /Debian/Ubuntu
sudo service nginx restart
We hope, the issue is resolved now.
Reason
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 server name is defined as “too.long.server.name.example.org” then nginx will fail to start and display the error.
If problem is not solved then the directive value should be increased to the next power of two like 32,64,128 etc.
Reference From : Nginx
It’s wrong not “html” block but “http” block instead.
Thank you!
Typo is corrected.
Regards
Sharad
I’d like to mention that I came across this error earlier and discovered that it was nothing to do with the bucket size config – it was because I had forgotten to put a semicolon at the end of the server_name line. Thus nginx was taking the rest of the config file as server names, filling the bucket. D’oh!
Thanks. It’s help me much.
Welcome Gregory
Regards
Sharad