$is_bot
The $is_bot variable is part of the device-type module for NGINX. It indicates whether the incoming request is from a bot or crawler. This variable is set during the request processing phase when the module detects bot-like characteristics based on predefined patterns.
Type
boolean (1/0)
Possible values
1: The request is identified as coming from a bot or crawler.0: The request is not identified as coming from a bot or crawler.
Examples
Access Control for Bots
This example shows how to block access to a specific location for bots.
location /sensitive-data {
if ($is_bot) {
return 403 "Access denied for bots";
}
proxy_pass http://backend;
}
Custom Header for Bot Requests
Add a custom header to requests identified as bots for logging or analytics purposes.
location / {
if ($is_bot) {
add_header X-Is-Bot "true";
}
proxy_pass http://backend;
}
Logging Bot Requests
Log requests from bots using a custom log format.
log_format bot_log '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"is_bot=$is_bot"';
access_log /var/log/nginx/bot_access.log bot_log;