📄 mod_authz_host.html
字号:
</code></p></div>
<p><code class="directive">Allow</code>指令的第三种参数格式允许对服务器的访问由<a href="../env.html">环境变量</a>的一个扩展指定。指定"<code>Allow from env=<var>env-variable</var></code>"时,如果环境变量<var>env-variable</var>存在则访问被允许。使用由<code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>提供的指令,服务器用一种基于客户端请求的弹性方式提供了设置环境变量的能力。因此,这条指令可以用于允许基于像<code>User-Agent</code>(浏览器类型)、<code>Referer</code>或其他HTTP请求头字段的访问。</p>
<div class="example"><h3>示例:</h3><p><code>
SetEnvIf User-Agent ^KnockKnock/2\.0 let_me_in<br />
<Directory /docroot><br />
<span class="indent">
Order Deny,Allow<br />
Deny from all<br />
Allow from env=let_me_in<br />
</span>
</Directory>
</code></p></div>
<p>这种情况下,发送以<code>KnockKnock/2.0</code>开头的用户代理标示的浏览器将被允许访问,而所有其他浏览器将被禁止访问。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="Deny" id="Deny">Deny</a> <a name="deny" id="deny">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>控制哪些主机被禁止访问服务器</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code> Deny from all|<var>host</var>|env=<var>env-variable</var> [<var>host</var>|env=<var>env-variable</var>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">覆盖项</a></th><td>Limit</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>基本(B)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_authz_host</td></tr>
</table>
<p>这条指令允许基于主机名、IP地址或者环境变量限制对服务器的访问。<code class="directive">Deny</code>指令的参数设置和<code class="directive"><a href="#allow">Allow</a></code>指令完全相同。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="Order" id="Order">Order</a> <a name="order" id="order">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>控制默认的访问状态与<code class="directive">Allow</code>和<code class="directive">Deny</code>指令生效的顺序</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code> Order <var>ordering</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>Order Deny,Allow</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">覆盖项</a></th><td>Limit</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>基本(B)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_authz_host</td></tr>
</table>
<p><code class="directive">Order</code>指令控制默认的访问状态与<code class="directive"><a href="#allow">Allow</a></code>和<code class="directive"><a href="#deny">Deny</a></code>指令生效的顺序。<var>Ordering</var>取值范围是以下几种范例之一:</p>
<dl>
<dt><code>Deny,Allow</code></dt>
<dd><code class="directive"><a href="#deny">Deny</a></code>指令在<code class="directive"><a href="#allow">Allow</a></code>指令之前被评估。<strong>默认允许所有访问</strong>。任何不匹配<code class="directive"><a href="#deny">Deny</a></code>指令或者匹配<code class="directive"><a href="#allow">Allow</a></code>指令的客户都被允许访问。</dd>
<dt><code>Allow,Deny</code></dt>
<dd><code class="directive"><a href="#allow">Allow</a></code>指令在<code class="directive"><a href="#deny">Deny</a></code>指令之前被评估。<strong>默认拒绝所有访问</strong>。任何不匹配<code class="directive"><a href="#allow">Allow</a></code>指令或者匹配<code class="directive"><a href="#deny">Deny</a></code>指令的客户都将被禁止访问。</dd>
<dt><code>Mutual-failure</code></dt>
<dd>只有出现在<code class="directive"><a href="#allow">Allow</a></code>列表并且不出现在<code class="directive"><a href="#deny">Deny</a></code>列表中的主机才被允许访问。这种顺序与"<code>Order Allow,Deny</code>"具有同样效果,不赞成使用。</dd>
</dl>
<p>关键字只能用逗号分隔;它们之间<strong>不能有空格</strong>。注意在所有情况下每个<code class="directive"><a href="#allow">Allow</a></code>和<code class="directive"><a href="#deny">Deny</a></code>指令语句都将被评估。</p>
<p>在下面的例子中,apache.org域中所有主机都允许访问,而其他任何主机的访问都将被拒绝。</p>
<div class="example"><p><code>
Order Deny,Allow<br />
Deny from all<br />
Allow from apache.org
</code></p></div>
<p>下面例子中,apache.org域中所有主机,除了foo.apache.org子域包含的主机被拒绝以外,其他都允许访问。而所有不在apache.org域中的主机都不允许访问,因为默认状态是拒绝对服务器的访问。</p>
<div class="example"><p><code>
Order Allow,Deny<br />
Allow from apache.org<br />
Deny from foo.apache.org
</code></p></div>
<p>另一方面,如果上个例子中的<code class="directive">Order</code>指令改变为"<code>Deny,Allow</code>",将允许所有主机的访问。这是因为,不管配置文件中指令的实际顺序如何,"<code>Allow from apache.org</code>"指令会最后被评估到并覆盖之前的"<code>Deny from foo.apache.org</code>"。所有不在<code>apache.org</code>域中的主机也允许访问是因为默认状态被改变到了<em>允许</em>。</p>
<p>即使没有伴随<code class="directive"><a href="#allow">Allow</a></code>和<code class="directive"><a href="#deny">Deny</a></code>指令,一个<code class="directive">Order</code>指令的存在也会影响到服务器上某一个部分的访问,这是由于它对默认访问状态的影响。例如:</p>
<div class="example"><p><code>
<Directory /www><br />
<span class="indent">
Order Allow,Deny<br />
</span>
</Directory>
</code></p></div>
<p>这样将会禁止所有对<code>/www</code>目录的访问,因为默认状态将被设置为<em>拒绝</em>。</p>
<p><code class="directive">Order</code>指令只在服务器配置的每个段内部控制访问指令的处理。这暗示着,例如,一个在<code class="directive"><a href="../mod/core.html#location"><Location></a></code>段中出现的<code class="directive"><a href="#allow">Allow</a></code>或<code class="directive"><a href="#deny">Deny</a></code>指令总是将会在一个<code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>段或者<code>.htaccess</code>文件中出现的<code class="directive"><a href="#allow">Allow</a></code>或<code class="directive"><a href="#deny">Deny</a></code>指令之后被评估,而不管<code class="directive">Order</code>指令如何设置。要了解配置段落合并的详细信息,参见<a href="../sections.html">配置段</a>文档。</p>
</div>
</div>
<div id="footer">
<p class="apache">本文允许自由使用、分发、转载,但必须保留译者署名;详见:<a href="../translator_announcement.html#announcement">译者声明</a>。</p>
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -