$browser_family
The $browser_family variable, provided by the device-type module, holds the family name of the browser making the request. It is set for each HTTP request processed by NGINX when the module is loaded.
Type
string
Possible values
ChromeFirefoxSafari
These values represent the main browser families detected by the module. Each value indicates the general category of the browser, which can be useful for tailoring responses based on browser capabilities or characteristics.
Examples
Using $browser_family in a map for Conditional Logic
You can use $browser_family in a map block to set a variable based on the browser family.
map $browser_family $is_modern_browser {
default 0;
Chrome 1;
Firefox 1;
Safari 1;
}
server {
location / {
if ($is_modern_browser) {
add_header X-Modern-Browser "true";
}
}
}
Adding a Header Based on Browser Family
Add a custom header to responses based on the detected browser family.
server {
location / {
add_header X-Browser-Family $browser_family;
proxy_pass http://backend;
}
}
Logging Browser Family in Access Logs
Include the browser family in your NGINX access logs for analytics purposes.
log_format custom '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$browser_family"';
access_log /var/log/nginx/access.log custom;