$device_brand
The $device_brand variable holds the manufacturer name of the device making the HTTP request. It is set by the device-type module when a request is processed, allowing NGINX to identify the brand of the device.
Type
string
Possible values
Apple: Represents devices manufactured by Apple Inc.Samsung: Represents devices manufactured by Samsung Electronics.Google: Represents devices manufactured by Google LLC.
Examples
Using $device_brand in a map
You can use $device_brand to map specific brands to custom values or actions.
map $device_brand $custom_header {
default "";
"Apple" "X-Apple-Device";
"Samsung" "X-Samsung-Device";
"Google" "X-Google-Device";
}
server {
location / {
add_header X-Device-Brand $custom_header;
proxy_pass http://backend;
}
}
Including $device_brand in log_format
Log the device brand for analytics purposes.
log_format custom '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$device_brand"';
access_log /var/log/nginx/access.log custom;
server {
location / {
proxy_pass http://backend;
}
}
Conditional access control with $device_brand
Restrict access to certain content based on the device brand.
server {
location /premium-content {
if ($device_brand = "Apple") {
return 403 "Access restricted for Apple devices";
}
proxy_pass http://backend;
}
}