Saltar a contenido

$bot_name

The $bot_name variable is set by the device-type module to identify the specific bot making a request. It is populated when a request is detected as originating from a bot.

Type

string

Possible values

  • Googlebot: Represents Google's web crawler.
  • GPTBot: Represents OpenAI's GPT-related crawler.
  • ClaudeBot: Represents Anthropic's Claude-related crawler.

These values indicate the specific bot detected from the request.

Examples

Adding Bot Name to Logs

Log the bot name for requests identified as bots.

http {
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$bot_name"';

    access_log /var/log/nginx/access.log main;
}

Conditional Access Control

Block specific bots from accessing certain paths.

location /sensitive-data {
    if ($bot_name = "GPTBot") {
        return 403 "Access denied for GPTBot";
    }
    proxy_pass http://backend;
}

Cache Key Composition

Include the bot name in the cache key to differentiate cached content based on the bot type.

proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m;

server {
    location / {
        proxy_cache my_cache;
        proxy_cache_key "$scheme$request_uri|$bot_name";
        proxy_pass http://backend;
    }
}