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
- $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 {
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.