您可以通过BrowserMatch拒绝访问,并可以从SetEnvIf示例拒绝:
SetEnvIfNoCase User-Agent "^Wget" bad_bot
SetEnvIfNoCase User-Agent "^EmailSiphon" bad_bot
SetEnvIfNoCase User-Agent "^EmailWolf" bad_bot
<Directory "/var/www">
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</Directory>
要永久阻止它们,您必须编写自定义日志文件并使用fail2ban例如使用iptables禁止它们
例如创建LogFormat
LogFormat "%a %{User-agent}i" ipagent
将日志记录添加到您的vhost /服务器范围内
CustomLog /var/log/apache2/useragent.log ipagent
/etc/fail2ban/filter.d/baduseragent.conf
[Definition]
failregex = ^<HOST> Mozilla/4\.0 \(compatible; MSIE 7\.0; Windows NT 5\.1; SV1; \.NET CLR 2\.0\.50727\) Havij$
/etc/fail2ban/jail.conf
[apache-bad-user-agent]
enabled = true
port = 80,443
protocol = tcp
filter = baduseragent
maxretry = 1
bantime = 86400
logpath = /var/log/apache2/useragent.log