Перейти к содержанию

$is_desktop

The $is_desktop variable is set by the device-type module to indicate whether a request originates from a desktop or laptop device. It is determined using precompiled regex patterns against the User-Agent string and client hints.

Type

Boolean (1/0)

Possible values

  • 1: The request is from a desktop or laptop.
  • 0: The request is not from a desktop or laptop.

Examples

Conditional Access Control

Use $is_desktop to restrict access to certain content for desktop users only.

location /desktop-only {
    if ($is_desktop = 0) {
        return 403 "Access restricted to desktop users only";
    }
    proxy_pass http://backend;
}

Cache Key Composition

Differentiate cache entries based on whether the request comes from a desktop device.

proxy_cache_key "$scheme$request_uri|$is_desktop";

Logging Device Type

Log whether the request came from a desktop device.

log_format main '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent" '
                'desktop=$is_desktop';

access_log /var/log/nginx/access.log main;