$os_family
The $os_family variable is set by the device-type module and holds the family classification of the operating system detected from the HTTP request. It is useful for tailoring responses based on the client's OS family.
Type
string
Possible values
Windows: Represents the Windows operating system family.Android: Represents the Android operating system family.Unix: Represents Unix-like operating systems.iOS: Represents the iOS operating system family.macOS: Represents the macOS operating system family.
Examples
Logging OS Family
To log the operating system family in your access logs:
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $os_family';
access_log /var/log/nginx/access.log main;
}
Conditional Header Setting
Set a custom header based on the OS family:
server {
location / {
if ($os_family = "iOS") {
add_header X-OS-Family "iOS User";
}
proxy_pass http://backend;
}
}
Cache Key Composition
Vary cache content by OS family:
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m;
server {
location / {
proxy_cache my_cache;
proxy_cache_key "$scheme$request_uri|$os_family";
proxy_pass http://backend;
}
}