是否可以使用基于文件的动态阻止列表阻止来自 IP 地址的用户?
所以,假设 .htaccess 看起来像:
order Deny,Allow
Deny from 123.156.0.1
Deny from 10.0.0.10
Allow from all
能否将此列表设为动态,例如:
order Deny,Allow
[include Deny list here]
Allow from all
另一个选择当然是用 PHP 修复它,但最好让 Apache 处理这个问题。
根据Apache docs,似乎无法从文本文件中读取值。
但是,您可以include
使用包含 IP 地址的配置文件。不过,它们必须采用 Apache 的 conf 文件格式。
这应该有效:
order Deny,Allow
include conf/IPList.conf
Allow from all
include
即使不推荐,它甚至可以用于整个目录。
我使用 Apache 的 RewriteModule 中的RewriteMap功能,作为这样的白名单:
## WHITELIST IPS ##
RewriteMap ipslist txt:/path/to/whitelist.txt
RewriteCond %{REMOTE_ADDR} ^(.*)$
RewriteCond ${ipslist:%1|black} ^black$ [NC]
RewriteRule (.*) - [F]
通过一些调整,您可以将其设为黑名单。