21
# Flag the bots or conditions you want to block without logging
map $http_user_agent $blocked_bot {
default 0;
~*badbot 1; # Example bot pattern
}
server {
listen 80;
# Main access log - requests blocked without logging won't appear here
access_log /var/log/nginx/access.log combined;
# Dummy log for blocked requests, you can ignore this file
# Alternatively, you can set it to /dev/null if you don't want to keep these logs at all
access_log /var/log/nginx/blocked.log combined if=$log_blocked;
# Regular location blocks and server configuration go here
if ($blocked_bot) {
set $log_blocked 0; # Do not log
rewrite ^ /blocked_bot last; # Redirect to a named location for handling
}
# Named location for handling blocked requests without logging
location @blocked_bot {
access_log off; # Disable logging for this location
return 403;
}
}