referer_hash_max_size
Sets the maximum size of the hash table used for storing referer data in NGINX.
Description
The referer_hash_max_size directive in NGINX is used to define the maximum size of the hash table that stores referer information from incoming requests. This directive plays an important role in memory management and performance tuning related to how referers are processed. When a client makes a request, NGINX can check their referer as part of access control or for logging purposes. This hash table is essentially a collection of stored referers that NGINX will maintain during its operation.
The value set for referer_hash_max_size determines how many entries can be accommodated in the hash table. If the maximum size is exceeded, NGINX may start to remove the least used entries or prevent new entries from being added, which can affect the application using referer information. Setting an appropriately sized table can help prevent performance degradation, particularly if your application has many different referer values, as it ensures that lookups remain efficient.
This directive can be set in both the server and location contexts, allowing for granular control over referer handling based on different virtual hosts or specific URL paths. The recommended usage is to analyze your access logs and tune the value based on the diversity of referer data observed to optimize memory usage and maintain performance.
Config Example
http {
referer_hash_max_size 64;
}Setting a very low value may cause legitimate referer requests to be ignored if they exceed the stored limit.
Increasing this value too much may lead to unnecessary memory consumption.
Ensure not to set this directive in inappropriate contexts to avoid configuration errors.