@vastlysuperiorman 说得对,csf/lfd 在这方面做得最好。不幸的是,它们只能在 linux 上运行。
This free utilitypromises to provide the same functionality:动态监控访问尝试并自动阻止 IP 地址。如果出现误报,您可以使用命令解除阻止。当然值得做空。
另一种方法是创建一个 VM(如果您的平台支持虚拟化)部署一个非常小的规格 linux 机器,并将其用作代理。这应该很容易实现。顺便说一句,为什么不只使用linux? .. :-)
(这应该是对 @vastlysuperiorman 帖子的评论,但我没有足够的 SO 代表来评论其他人的帖子)
Edited to suggest a possible apache 2.4 based solution:
在apache中翻译2.2和2.4之间的ACL指令
2.2 语法
order Deny,Allow
include conf/IPList.conf
Allow from all
2.4 语法
DocumentRoot /some/local/dir
<Directory /some/local/dir/>
<RequireAll>
Require all granted
Include conf/IPList.conf
</RequireAll>
</Directory>
#this will also work
<Location />
<RequireAll>
Require all granted
Include conf/IPList.conf
</RequireAll>
</Directory>
# conf/IPLIst.com is actually in /etc/apache2/conf/IPList.conf
# (ie, paths are relative to where apache is installed.
# I guess you can also use the full path to the list.
在 conf/IPList.conf 中,您将有单独的行,其中包含如下条目
不需要 ip 10.10.1.23
不需要 ip 192.168.22.199
不需要 ip 10.20.70.100
使用 mod-rewrite 和 IP 列表进行封禁
- 要使重定向到另一个页面起作用,您需要将 RewriteRule 保留在您要保护的基本 URL 之外。
- 例如,重定向在 DocumentRoot 上的 Directory 指令或“/”上的 Location 指令下不起作用,因为禁令会影响我们要显示的状态页面。
- 因此,最好将其保留在 Directory 或 Location 指令之外,或链接到另一个未受保护的 Web 服务器上的状态页面。
#Required set of rewrite rules
RewriteEngine on
RewriteMap hosts-deny txt:/etc/apache/banned-hosts
RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^ /why-am-i-banned.html
## inside our banned hosts file, we have:
## /etc/apache2/banned-hosts (maintain the format .. its not just a plain text file)
##
193.102.180.41 -
192.168.111.45 -
www.example.com -
www.sumwia.net -
# inside our status page, could be html as below or a plain text file with '.txt' extension
#/var/www/html/why-am-i-banned.html
#
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Why is my IP banned?</title>
</head>
<body>
<h2>Why is my IP address banned?</h2>
<p>
To manage spammers and for other security needs, our server automatically blocks
suspicious IP address. If however you reckon your IP address has been blocked
wrongfully, please contact us.
</p>
</body>
</html>
当然,您可以解析日志文件并根据需要填充 conf/IPList.conf 或 /etc/apache2/banned-hosts ..
作为短期解决方案
允许您使用 2.2 语法的替代方法是安装 mod_access_compat 模块并继续使用已弃用的 2.2 样式“拒绝,允许”指令。但这仅作为短期解决方案是可取的,因为该模块只是用于帮助过渡,并且可能会在 apache 2.4 的未来版本中消失