我正在更新我的原始问题,因为我很困惑"不要主持"对于引用者字符串中包含的主机名。
所以我现在需要确定。在Apache 2.2中,我正在执行以下操作以允许/拒绝某些IP范围,用户代理和域名/引用。
这是一个非常简短的例子,因为我不想用太多代码给任何人带来负担。我已经测试了Apache 2.4代码块,它似乎运行正常,但现在是正确的做法吗?
是否有必要像以前一样指定列入白名单的IP和域名,或者只是因为Require all granted
??
只要加载 mod_access_compat 模块,旧的2.2方法就可以100%在Apache 2.4上运行,但显然在不使用兼容性模块的情况下为Apache 2.4做正确的事情是一等奖。
Apache 2.2:
<Directory /var/www/html>
Order Allow,Deny
Allow from all
Allow from env=good_bot
Allow from env=good_ref
Allow from 131.253.24.0/22
Allow from 131.253.46.0/23
deny from 104.197.51.76
deny from 108.167.189.81
deny from env=bad_bot
deny from env=spam_ref
</Directory>
Apache 2.4:
<Directory /var/www/html>
<RequireAny>
<RequireAll>
Require all granted
Require not ip 104.197.51.76
Require not ip 54.242.250.203
Require not env bad_bot
Require not env spam_ref
</RequireAll>
<RequireAny>
Require ip 131.253.24.0/22
Require ip 131.253.46.0/23
Require env good_ref
Require env good_bot
</RequireAny>
</RequireAny>
</Directory>
答案 0 :(得分:2)
我可以确认我的apache 2.4示例是正确的。我已经测试了大量的推荐人,用户代理,黑名单和白名单ip,它看起来很完美。我还通过卸载mod_access_compat模块并使用a2dismod access_compat
所以现在这是在Apache 2.4中执行操作的正确方法。
<Directory /var/www/html>
<RequireAny>
<RequireAll>
Require all granted
Require not ip 104.197.51.76
Require not ip 54.242.250.203
Require not env bad_bot
Require not env spam_ref
</RequireAll>
<RequireAny>
Require ip 131.253.24.0/22
Require ip 131.253.46.0/23
Require env good_ref
Require env good_bot
</RequireAny>
</RequireAny>
</Directory>