我从apache网站上阅读了这个指南,但是我有点困惑,我试图用这种语法禁用一些范围:
order allow,deny deny from 127.0.55.0/127.0.75.255 deny from 127.0.235.0/127.0.255.255 allow from all
但我认为它不能正常工作,可能是语法错误或者我以错误的方式使用它,我应该在htaccess中写这个文本?在其他线之前或之后?在同一个htaccess文件中也有一些mod重写脚本(用于反链接).
我正在更新我原来的问题,因为我对引用字符串中包含的主机名混淆了“不需要主机”。
所以我现在需要确定的是。在 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 …Run Code Online (Sandbox Code Playgroud)