有没有办法简化对apache httpd.conf文件中特定源IP的访问限制

有没有办法简化对apache httpd.conf文件中特定源IP的访问限制,apache,Apache,例如,这是我的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

例如,这是我的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)
...
。。。
命令拒绝,允许
全盘否定
从x.x.x.x允许
(和其他“从x.x.x.x允许”)
命令拒绝,允许
全盘否定
从x.x.x.x允许
(和其他“从x.x.x.x允许”)
(和具有相同ip限制的其他位置)
...
位置内
标记是相同的ip限制,有数百个ip。那么如何简化它呢?

您可以将其放在文档根目录的“”块中,而不是将“allow from”放在每个位置中。 另一种选择是使用重写规则并将其置于virtualhost级别(或根据您的配置置于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]