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
- $device_type
- $is_mobile
- $is_tablet
- $is_desktop
- $is_bot
- $is_tv
- $is_console
- $is_wearable
- $device_brand
- $device_model
- $browser_name
- $browser_version
- $browser_family
- $browser_engine
- $os_name
- $os_version
- $os_family
- $bot_name
- $bot_category
- $bot_producer
- $is_ai_crawler
- $device_json
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.