What the message looks like
nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
nginx: configuration file /etc/nginx/nginx.conf test failedCommon causes
- One
server_nameis very long (for example a long subdomain), and a bucket is too small for it. - Many server names were added across
serverblocks, so the table needs a larger size. - The same name is listed in several places because a file is included twice, which inflates the table.
- A generated config (wildcard lists, many aliases per site) was added without raising the hash settings.
Check
- Run the configuration test
nginx -t - Current hash settings, if any
nginx -T 2>/dev/null | grep -nE 'server_names_hash' - The longest configured server names
nginx -T 2>/dev/null | grep -E '^\s*server_name' | tr -s ' ;' '\n' | awk 'length > 25' | sort -u - Is a file included twice?
nginx -T 2>/dev/null | grep -E '^# configuration file' | sort | uniq -d
Fix
- Add to the
httpblock in/etc/nginx/nginx.conf:server_names_hash_bucket_size 128;(a power of two; the message names the current value). - If the error stays or you have hundreds of names, also raise
server_names_hash_max_size, for example1024. - Remove duplicate includes so no name is defined twice.
- Test and apply:
nginx -t && systemctl reload nginx.
FAQ
Which value should I use?
Double the value from the message and try again: 64 becomes 128, then 256 if needed. The bucket size must be a power of two.
Why does it appear after adding one more domain?
The table is sized when the configuration loads. One more or one longer name can be the one that no longer fits, even though the old setup worked.