• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Nginx : could not build the server_names_hash, you should increase server_names_hash_bucket_size

November 29, 2014 by Sharad Chhetri 5 Comments

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

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Can’t load ‘/usr/local/lib64/perl5/auto/nginx/nginx.so’
  2. How to increase Password Expire date without resetting the password
  3. Python headers are required to build Mercurial but weren’t found
  4. Increase upload file size limit in php
  5. How to run django with nginx
  6. How to install nginx webserver from source on CentOS and RHEL
  7. Setup htpasswd on WordPress wp-admin running on nginx
  8. Install Nginx from source code on Ubuntu 14.04 LTS
  9. Install and compile nginx 1.14 on Ubuntu 18.04 LTS server
  10. How To Install Nginx On Ubuntu 22.04 LTS

Filed Under: Linux Tagged With: nginx

Reader Interactions

Comments

  1. Sharad Chhetri says

    September 17, 2017 at 1:51 pm

    Thank you!

    Typo is corrected.

    Regards
    Sharad

  2. John Doe says

    September 17, 2017 at 7:00 am

    It’s wrong not “html” block but “http” block instead.

  3. Dave says

    August 16, 2017 at 11:02 am

    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!

  4. sharad chhetri says

    December 14, 2014 at 7:07 pm

    Welcome Gregory

    Regards
    Sharad

  5. Gregory Campos Pacheco says

    December 14, 2014 at 5:06 pm

    Thanks. It’s help me much.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Commands

yum : how to find rpm package which has certain command or file

Save iptables permanently on Ubuntu

Useful tail command with examples in Linux/Unix

Linux Basic Commands With Examples For Every Beginner

cat,sed and awk commands to display file contents

type Command : Display Information About Command Type On Linux

How to test rpm package before installation

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

How to install pam_mysql in CentOS or Red Hat

30 useful Linux terminal keyboard shortcuts

find command to search keyword in files recursively in linux

How To Get SSH Public Key Fingerprint Information

curl command to check the http status

How to use grep command to get fixed pattern or exact keyword

Keep logs of user after sudo su – : Secondary Logging

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Internal External Command

What is Linux/Unix Internal And External Command

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy