$device_model
The $device_model variable holds the model name of the device making the HTTP request. It is set when the device-type module is loaded and detects a known device model from the request headers.
Type
string
Possible values
iPhone 15Galaxy S24Pixel 8
These values represent specific models of devices such as smartphones or tablets.
Examples
Using $device_model in a log_format
Log the device model for each request to analyze traffic by device type.
http {
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$device_model"';
access_log /var/log/nginx/access.log main;
}
Adding a custom header with $device_model
Pass the device model to the backend server as a custom header.
location /api/ {
proxy_pass http://backend;
proxy_set_header X-Device-Model $device_model;
}
Conditional response based on $device_model
Return a specific message if the request comes from a particular device model.
location /special-offer {
if ($device_model = "iPhone 15") {
return 200 "Exclusive offer for iPhone 15 users!";
}
return 404;
}