我正在更新我原来的问题,因为我对引用字符串中包含的主机名混淆了“不需要主机”。
所以我现在需要确定的是。在 Apache 2.2 中,我执行以下操作来允许/拒绝某些 IP 范围、用户代理和域名/引荐来源网址。
这是一个非常简短的示例,因为我不想给任何人带来太多的代码负担。我已经测试了 Apache 2.4 代码块,它看起来工作正常,但现在是正确的处理方式吗?
是否有必要像我之前那样指定列入白名单的 IP 和域,还是只需要由于Require all granted??而将其列入黑名单?
只要加载mod_access_compat模块,旧的 2.2 方法就可以 100% 在 Apache 2.4 上工作,但显然,在不使用兼容性模块的情况下为 Apache 2.4 做好准备是一等奖。
阿帕奇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>
Run Code Online (Sandbox Code Playgroud)
阿帕奇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>
Run Code Online (Sandbox Code Playgroud)
我可以确认我的 apache 2.4 示例是正确的。我已经用大量的引荐来源网址、用户代理、黑名单和白名单 IP 对其进行了测试,它看起来很完美。我还通过卸载 mod_access_compat 模块并重新加载 apache 来确认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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4448 次 |
| 最近记录: |