Nginx: [Emerg] Could Not Build the Server_names_hash, You Should Increase Server_names_hash_bucket_size
The error [Emerg] could not build the server_names_hash, you should increase the hash size
in Nginx occurs when the number of server names in your configuration exceeds the default hash table size, leading to a failure in building the server name hash table. This issue usually arises when you have many server names or domains in your Nginx configuration.
To resolve this, you need to increase the hash table size for server names by adjusting the server_names_hash_max_size
and optionally server_names_hash_bucket_size
directives in your Nginx configuration. Here’s how you can address this issue:
1. Modify Nginx Configuration
You need to increase the server_names_hash_max_size
in your Nginx configuration. If you also have very long server names or many server names, you may also need to adjust the server_names_hash_bucket_size
.
Edit the Nginx Configuration File:
- Typically, the main configuration file is located at
/etc/nginx/nginx.conf
. - You might need to edit this file or create a configuration file in the
.conf
directory (e.g.,/etc/nginx/conf.d/
).
Example Configuration:
http {
# Increase the size of the hash table used for server names
server_names_hash_max_size 2048;
# Optional: Increase the size of the hash bucket if needed
server_names_hash_bucket_size 64;
# Other settings...
}
Explanation:
server_names_hash_max_size
: Sets the maximum size of the hash table for server names. Increase this value if you have many server names.server_names_hash_bucket_size
: Sets the size of the hash buckets. Increase this if you have long server names or if you encounter aHash Bucket Size
error.
2. Restart Nginx
After updating the configuration file, restart Nginx to apply the changes.
Restart Command:
sudo systemctl restart nginx
Alternative Command (if using init.d):
sudo service nginx restart
3. Verify the Changes
Check the Nginx error log to ensure that the configuration changes were applied successfully and that the server starts without errors.
Check Nginx Error Log:
sudo tail -f /var/log/nginx/error.log
Explanation:
f
: Follows the log output in real-time.
4. Adjust as Needed
If you still encounter issues, you might need to adjust the values further:
- Increase
server_names_hash_max_size
: If you continue to have issues with server names hash size. - Increase
server_names_hash_bucket_size
: If you have very long server names or if the bucket size error persists.
5. Example of Common Configurations
Default Configuration (for small number of server names):
http {
server_names_hash_max_size 512;
server_names_hash_bucket_size 32;
}
For Larger Number of Server Names or Long Server Names:
http {
server_names_hash_max_size 2048;
server_names_hash_bucket_size 64;
}
Summary
To resolve the [Emerg] could not build the server_names_hash
error in Nginx:
- Modify Configuration: Increase
server_names_hash_max_size
and optionallyserver_names_hash_bucket_size
in the Nginx configuration file. - Restart Nginx: Apply the changes by restarting Nginx.
- Verify Changes: Check logs to ensure the configuration is correct and Nginx starts without errors.
- Adjust as Needed: Fine-tune the hash size settings based on your specific needs.
By following these steps, you can effectively address and resolve the server names hash table size issue in Nginx.
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github