The original post: /r/nginx by /u/Yakuwari on 2024-09-12 17:45:24.

I’m trying to divide my logs between obvious bots and the rest. I use these maps:

map $http_user_agent $is_bot {
    default 0;  # 0 means non-bot
    "~*bot" 1;  # 1 means bot
    "~*crawl" 1;
    "~*spider" 1;
    "~*slurp" 1;
    "~*googleother" 1;
}
map $http_user_agent $is_not_bot {
    default 1;  # 1 means non-bot
    "~*bot" 0;  # 0 means bot
    "~*crawl" 0;
    "~*spider" 0;
    "~*slurp" 0;
    "~*googleother" 0;
}
access_log /var/log/nginx/access_non_bots.log combined if=$is_not_bot;
access_log /var/log/nginx/access_bots.log combined if=$is_bot;

Is there any easier way to do this?