Saltar a contenido

Device detection module for NGINX

Device detection module for NGINX

This module helps sysadmins and SREs identify device types, improving content delivery and bot management.

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 AI bots like GPTBot and ClaudeBot.
  • Analytics enrichment: Pass device context to backends.

Variables provided

Quick start

load_module modules/ngx_http_device_type_module.so;

server {
    location / {
        if ($is_mobile) {
            rewrite ^(.*)$ /m$1 last;
        }
    }

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

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

When NOT to use this module

  • If your application requires real-time device detection with frequent updates, the precompiled regex patterns may not cover all edge cases.
  • For very high traffic scenarios, consider the performance impact of additional processing at the edge.

See also