Pular para conteúdo

$bot_category

The $bot_category variable is set by the device-type module to categorize bots accessing your NGINX server. It identifies the type of bot, such as a search engine or an AI crawler, based on the request patterns.

Type

string

Possible values

  • search_engine: Indicates the bot is a search engine crawler.
  • ai_crawler: Identifies the bot as an AI training or data collection crawler.
  • crawler: General category for bots that do not fit into the other specific categories.

Examples

Access Control for AI Crawlers

Use $bot_category to block AI crawlers from accessing certain paths.

location /sensitive-data/ {
    if ($bot_category = "ai_crawler") {
        return 403 "Access denied for AI crawlers";
    }
    proxy_pass http://backend;
}

Custom Logging for Bot Traffic

Log bot traffic with specific categories for better analytics.

log_format bot_logging '$remote_addr - $remote_user [$time_local] '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent" '
                      'BotCategory=$bot_category';

access_log /var/log/nginx/bot_access.log bot_logging;

Cache Key Composition

Differentiate cache entries based on bot category to optimize cache efficiency.

proxy_cache_key "$scheme$request_uri|$bot_category";