Common causes
- A long domain name, such as a long subdomain or cloud hostname
- Many server names across all server blocks
- server_names_hash_bucket_size left at its default, which depends on CPU cache line size (32 or 64)
- The directive was added inside a server block instead of the http block
- Duplicate or wildcard-heavy server_name lists
How to fix it
- Raise the bucket size. In /etc/nginx/nginx.conf, inside the http { } block, add server_names_hash_bucket_size 128;. On Ubuntu there is often a commented line you can uncomment and edit.
- Raise max size if mentioned. If the error also names server_names_hash_max_size, add server_names_hash_max_size 1024; (or 2048 for very many names) in the http block.
- Place it in the http context. These directives are only valid in http { }. Putting them in a server block causes a different error.
- Test the config. Run sudo nginx -t. If it still fails, double the value again (bucket size should stay a power of two, like 128 or 256).
- Reload Nginx. Run sudo systemctl reload nginx. Check that all sites respond.
Increase hash sizes in /etc/nginx/nginx.conf
http {
server_names_hash_bucket_size 128;
server_names_hash_max_size 1024;
# ...
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
} How to stop it happening again
- Set the hash sizes in your base Nginx template
- Run nginx -t before reloading on every domain addition
- Remove old domains you no longer serve
- Avoid duplicate names across server blocks