apache - 有什么方法可以简化对 apache httpd.conf 文件中特定源 IP 的访问限制
问题描述
例如,这是我的 httpd.conf:
...
<Location /a>
Order deny,allow
Deny from all
Allow from x.x.x.x
(and other "Allow from x.x.x.x")
</Location>
<Location /b>
Order deny,allow
Deny from all
Allow from x.x.x.x
(and other "Allow from x.x.x.x")
</Location>
(and other locations with same ip restrict)
...
标签里面Location
都是相同的ip限制,有上百个ip。那么如何简化呢?
解决方案
您可以将其放在文档根目录的“”块中,而不是将“允许来自”放在每个位置内。另一种选择可能是使用重写规则并将其放置在虚拟主机级别(或根据您的配置在 httpd.conf 中):
RewriteCond %{REMOTE_ADDR} ^214.53.25.(6[4-9]|7[0-9]|8[0-9]|9[0-9])$ [OR]
RewriteCond %{REMOTE_ADDR} ^214.53.25.1([0-1][0-9]|2[0-8])$
RewriteRule .* - [F]
推荐阅读
- haskell - Verify RSA signature with public key in PEM format in Haskell
- php - 在 Laravel 的 Eloquent 查询中使用“with”时如何添加 where 子句
- c - 了解汇编与 C 对应物
- java - Tab 块中的所有行
- c# - 为什么 POCO 对象是使用类而不是结构创建的
- angular - Angular:图像未在生产中加载
- mysql - ,(comma) 和 and in group by 有什么区别?
- kubernetes - 如何修复 Windows 10 上 minikube 版本 0.33.1 的 minikube 安装失败?- 重新启动集群时出错 - 加载 apiserver 证书失败
- c++ - 矩阵中的 GECODE 成对不同的列
- c++ - 有没有办法让程序打开一个新的控制台窗口并使用 C/C++ 返回信息?