vhost_traffic_status_filter_by_host
The `vhost_traffic_status_filter_by_host` directive enables filtering traffic statistics based on the host.
Description
The vhost_traffic_status_filter_by_host directive is part of the NGINX virtual host traffic status module. When enabled, it allows users to filter traffic statistics by the host header of incoming requests. This is particularly useful in multi-tenant environments where different hosts might be served by the same NGINX instance, enabling you to track and analyze traffic metrics for each host individually.
The directive takes a single argument, which can be a flag value (usually on or off). When set to 'on', the directive will enable host-based filtering, and any gathered traffic statistics will be segmented by the respective hostname. Conversely, setting it to 'off' will disable this feature, and all traffic statistics will be aggregated without distinction by host. The general behavior of this directive makes it an essential tool for operators looking to gain visibility into their traffic patterns across different virtual hosts served by the NGINX instance.
This directive can be used in the contexts of http, server, and location blocks, which provides flexibility depending on how granular traffic filtering needs to be. For instance, it can be set globally in the http block for all servers or overridden in specific server or location blocks to achieve tailored levels of control and reporting accuracy for different applications.
Config Example
http {
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
server {
listen 80;
server_name example.com;
}
server {
listen 80;
server_name another-example.com;
}
}Ensure that the vhost_traffic_status_zone directive is properly configured and enabled, as this directive relies on it.
Be cautious when enabling filtering in high-traffic environments, as performance metrics might change due to the additional processing required for filtering.
When filtering by host, ensure that your server_name directives are correctly set to avoid misreported statistics.