apache - 仅允许通过 .htaccess 的 cloudflare ip 范围给出 403 错误
问题描述
我一直试图在我的服务器上只允许 cloudflares ip 范围,但我不断收到 403 错误,403 是绕过 cloudfare 的人应该看到的
我试过了
#cloudflare
order deny,allow
Deny from all
#ipv4
allow from 173.245.48.0/20
allow from 103.21.244.0/22
allow from 103.22.200.0/22
allow from 103.31.4.0/22
allow from 141.101.64.0/18
allow from 108.162.192.0/18
allow from 190.93.240.0/20
allow from 188.114.96.0/20
allow from 197.234.240.0/22
allow from 198.41.128.0/17
allow from 162.158.0.0/15
allow from 104.16.0.0/12
allow from 172.64.0.0/13
allow from 131.0.72.0/22
#ipv6
allow from 2400:cb00::/32
allow from 2606:4700::/32
allow from 2803:f800::/32
allow from 2405:b500::/32
allow from 2405:8100::/32
allow from 2a06:98c0::/29
allow from 2c0f:f248::/32
我试过了
DenyAllButCloudFlare
我遇到了同样的问题,上面的行给了我 500 错误
对于我的生活,我无法弄清楚,cloudflare 支持只是将我推荐到我关注的白名单页面
我正在使用 Apache 2.4.2
编辑:更改 Apache 版本号 :)
解决方案
尝试在 Apache 中使用 Require 指令。Apache自己提到:
mod_access_compat 提供的 Allow、Deny 和 Order 指令已被弃用,并将在未来的版本中消失。您应该避免使用它们,并避免推荐使用它们的过时教程。
尝试将其更改为,并确保 mod_authz_host 已启用:
#path to your website
<Directory "path/to/public_html/or/var/www/html">
#ipv4
Require ip 173.245.48.0/20
Require ip 103.21.244.0/22
Require ip 103.22.200.0/22
Require ip 103.31.4.0/22
Require ip 141.101.64.0/18
Require ip 108.162.192.0/18
Require ip 190.93.240.0/20
Require ip 188.114.96.0/20
Require ip 197.234.240.0/22
Require ip 198.41.128.0/17
Require ip 162.158.0.0/15
Require ip 104.16.0.0/12
Require ip 172.64.0.0/13
Require ip 131.0.72.0/22
#ipv6
Require ip 2400:cb00::/32
Require ip 2606:4700::/32
Require ip 2803:f800::/32
Require ip 2405:b500::/32
Require ip 2405:8100::/32
Require ip 2a06:98c0::/29
Require ip 2c0f:f248::/32
</Directory>
查看https://httpd.apache.org/docs/2.4/howto/access.html了解更多信息。
请注意这一点:Cloudflare 自己说:我认为无论如何使用普通的 Apache 指令应该会更好
Cloudflare 不再更新和支持 mod_cloudflare,从 Linux 操作系统的 Debian 9 * 和 *Ubuntu 18.04 LTS 版本开始。我们现在支持使用 Apache Web 服务器的客户使用 mod_remoteip。有兴趣构建 mod_cloudflare 包的客户可以从 GitHub 下载代码库。
而且 mod_remoteip 感觉它不安全。所以,我建议你坚持使用 Require ip 指令。
推荐阅读
- xamarin.forms - 将扬声器中的音频切换到耳机和耳机到扬声器
- pdf - 在 Xstring 变量中将智能表单转换为 PDF
- swift - 有一个数组的闭包数量不定,如何嵌套?
- python - 如何结合使用 Atom 和 Anaconda,或者将 Atom 连接到正在运行的 Jupyter 内核?
- javascript - reCaptcha v3 与 JSP 的集成
- html - 如何从表中删除选定的列?Angular?
- react-native - 使用 expo 反应原生消息队列
- postgresql - Postgres 中的“图像”类型是什么?
- jquery - 如何将当前时间和日期设置为 cookie?
- c++ - 使用自动说明符获取 lambda 的参数类型