server_names_hash_bucket_size

Sets the size of the hash bucket for storing server names.

Syntaxserver_names_hash_bucket_size size;
Default32
Contexthttp
Arguments1

Description

The "server_names_hash_bucket_size" directive in NGINX controls the size of the hash buckets utilized to store server names in the configuration. When multiple server names are defined, NGINX hashes these names to improve lookup efficiency and speed in matching incoming requests against the defined server blocks. The size of the buckets affects the efficiency of the hash table: smaller sizes can lead to collisions, forcing the hash table to resolve them, potentially impacting performance. The directive is essential for configurations with numerous or long server names, as it allows fine-tuning of memory consumption and performance characteristics.

The parameter for this directive is specified in bytes, and the value should generally be a power of two. Choosing appropriate values depends on the specific server's usage and the number of server names defined. For scenarios where there are many server names or particularly lengthy names, increasing the bucket size can help maintain efficient hash resolution, as each bucket should ideally contain fewer entries to minimize lookup times. It's important to avoid excessively large values that could lead to wasted memory, depending on the server's configuration and load.

Config Example

http {
    server_names_hash_bucket_size 64;
}

Setting the value too low may lead to hash collisions, negatively impacting performance.

Using values that are not a power of two may lead to suboptimal bucket allocation.

← Back to all directives