English 中文(简体)
外部文件中的 ip s 列表拒绝 Apache 拒绝
原标题:Apache deny from list of ip s in external file
  • 时间:2012-05-24 13:19:45
  •  标签:
  • apache

I d like to maintain a file which includes a list of ip s which are blocked from using a site. I understand deny from can be used to achieve this (e.g Deny from 127.0.0.1 10.0.0.1 some.other.ip.address).

但我喜欢外部文件, 这样无法访问配置的个人就可以用 ips 更新 txt 文件, 从而写入拒绝文件 。

有谁对如何实现这一点有任何建议吗?任何帮助都得到了极大的支持。

最佳回答

看看阿帕奇语包含指令 :

http://http://httpd.apache.org/docs/2.2/mod/core.html#including

您可以创建一个包含您拒绝的列表的分隔配置文件, 并在其他配置文件, 即站点可用的站点中包含此文件。 示例如下 :

在/etc/apache2/ sites-powed/ your site.conf 中,在/etc/apache2/ sites-powed/ your site.conf 中,在/etc/pache2/ sites-powed/ yours.conf 中,在/etc/apache2/ sites-pounded/ yoursite.conf 中,在/etc/pache2/s-petf 中,在/etc/pache2/ sites-powed/ yoursite.conf 中,在/etc/pache2/ sites-papeded/ yoursite.conf 中,在/ ac.conf 中,在/ ac/ ac/ ac/ ac/achec/achec/achec/achec/ache/ache2-sept---sept----sept------------------------------------------------------------------

<VirtualHost *:80>
...

Include /etc/apache2/sites-access/yoursite.conf

...
</VirtualHost>

在/etc/apache2/ sites-access/ your site.conf 中,在/etc/apache2/ sites-access/ yoursite.conf 中,在/etc/apache2/ sites-access/ yoursite.conf 中,在/etc/apache2/ sites-access/ yoursite.conf 中,在/etc/apache2/ sites-access/ yoursite.conf 中,在/etc/apache2/s-access-access/ yoursite.conf 中,在/etc/ac/ache2/s-access-access/ yourserf.conf 中,在/etc/ache/ache/ache/ache/ache/ache2/serf.conf.conf 中,在/ac.c/ac/ac/ache/ache/ache/ac/ac/ache2/s/ac/ac/ache2/s/ac/ache2/s/ache2/s/ache2/s-ache2/c/c/ache2/scc

order allow,deny
deny from 10.0.0.1
allow from all
问题回答

使用 RewriteMap 地图作为外部 IP 地址文件,用于单个 IP 地址列表 :

RewriteEngine on
RewriteMap allowed "txt:${site_dir}/etc/allowed_ip_addresses"

UnsetEnv ALLOWED

RewriteCond ${allowed:%{REMOTE_ADDR}} 1
RewriteRule ^ - [E=ALLOWED]

<Location />
  Deny  from all
  Allow from env=ALLOWED
</Location>

然后 liberted_ip_addresses 中包含诸如 :

10.42.1.123      1
192.168.100.456  1

该地图允许 IP 地址为 1 值, 而其他所有 IP 地址为空字符串 。

RewriteCond 在地图中查找 reMOTE_ADR ,如果它是 1 ,则设置环境变量。 unsetEnv 确保该变量绝对无法另设。

然后Allow from 只能在该环境变量设定时允许访问。

外部地图文件可以拥有与您的 Apache 配置不同的文件系统权限, 且更改会立即生效, 无需重新启动 Apache 。

这不是一个真正的安全方法, 但是您可以将这个 txt 文件放在共享目录中, 并用一个 cron 任务更新 apache 配置...

另一种方法是 Htaccess 。

order allow,deny
deny from 10.0.0.1
allow from all
 In windows httpd.conf 
 <Directory /> 
 Include "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/deny.txt" 
 </Directory> 
 deny.txt contain 
 Deny from xxx.xxx.xxx.xxx 
 etc 

我使用.htaccess、一个文件夹和一份以被禁 ip 为标题的文件列表,

如果禁用的 IP 文件存在, 那么返回被禁止的旗帜 :

RewriteCond "%{DOCUMENT_ROOT}/banned_ips/%{HTTP:X-FORWARDED-FOR}" -f
RewriteRule .* - [F]

我的例子为 AWS 云端,但您可以用 < code> HTTP:X-forward-for 替换 < code> HTTP:X-forward-for 或含有访客 ip 的任何变量替换

您也可以使用 HTTP_HOST 来保存按网站分类的目录, 如 :

RewriteCond "%{DOCUMENT_ROOT}/banned_ips/%{HTTP_HOST}/%{HTTP:REMOTE_ADDR}" -f
RewriteRule .* - [F]

这样你就不会需要更新您的 htaccess 文件, 甚至也可以在程序上从蜂窝中添加 IP, 列出我们自己的追踪器 。

请在评论中让我了解你对这一方法在可缩放性和(或)安全性方面的看法。

从Apache httpd 版本2.3.6到以后,您可以使用该指令。

IncludeOptional /etc/myfilewithrequireip.conf

https://https://httpd.apache.org/docs/2.4/mod/core.html#including optional" rel=“nofollown noreferrer'>>https://https://httpd.apache.org/docs/2.4/mod/core.html#includingoptional

也有可能使用包含, 但如果文件 conf 不存在, 将会报告错误 。





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签