Saltar a contenido

Device detection module for NGINX

Comprehensive device detection at the NGINX edge. Classifies HTTP requests by device type, browser, operating system, and bot classification using 3,600+ regex patterns.

Why use this module

  • Adaptive serving: Serve mobile-optimized assets without redirects.
  • Cache segmentation: Vary cached content by device type.
  • Bot management: Block scrapers, rate-limit crawlers, allow search engines.
  • AI crawler control: Identify and manage GPTBot, ClaudeBot, and other AI training bots.
  • Analytics enrichment: Pass device context to backends.

Variables provided

Quick start

load_module modules/ngx_http_device_type_module.so;

server {
    # Serve different content by device
    location / {
        if ($is_mobile) {
            rewrite ^(.*)$ /m$1 last;
        }
    }

    # Block AI crawlers
    location /content/ {
        if ($is_ai_crawler) {
            return 403;
        }
        proxy_pass http://backend;
    }

    # Debug endpoint
    location = /device {
        default_type application/json;
        return 200 $device_json;
    }
}

When NOT to use this module

  • If your NGINX setup is constrained by memory, as regex pattern compilation and caching can increase resource usage.
  • If device detection is not critical to your application, consider simpler solutions to reduce complexity.

See also