$browser_name
The $browser_name variable in NGINX is set by the device-type module. It holds the name of the browser making the HTTP request, such as Chrome, Firefox, or Safari.
Type
string
Possible values
Chrome: Represents the Google Chrome browser.Firefox: Represents the Mozilla Firefox browser.Safari: Represents the Apple Safari browser.
Examples
Logging the Browser Name
To log the browser name in your access logs, you can include the $browser_name variable in a custom log_format.
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$browser_name"';
access_log /var/log/nginx/access.log main;
}
Adding a Header with the Browser Name
You can pass the browser name to the backend server by adding it as a custom header.
location / {
proxy_set_header X-Browser-Name $browser_name;
proxy_pass http://backend;
}
Conditional Redirect Based on Browser
Redirect users to a specific page if they are using a particular browser.
location / {
if ($browser_name = "Safari") {
return 302 /safari-special-page;
}
proxy_pass http://backend;
}