📄 mod_authz_host.html
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_authz_host - Apache 2.2 中文版参考手册</title>
</head>
<body><div id="page-header">
<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><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">文档</a> > <a href="../index.html">版本2.2</a> > <a href="./index.html">模块</a></div>
<div id="translation-info"> <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<a href="mailto:csfrank@citiz.net">金步国</a> | 本篇译稿最后更新:2006年1月24日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_authz_host</h1>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>提供基于主机名、IP地址、请求特征的访问控制</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>基本(B)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>authz_host_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_authz_host.c</td></tr>
<tr><th><a href="module-dict.html#Compatibility">兼容性</a></th><td>仅在 Apache 2.1 及以后的版本中可用</td></tr>
</table>
<h3>概述</h3>
<p><code class="module"><a href="../mod/mod_authz_host.html">mod_authz_host</a></code>提供的指令用在<code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>, <code class="directive"><a href="../mod/core.html#files"><Files></a></code>, <code class="directive"><a href="../mod/core.html#location"><Location></a></code>段中,也用于<code><a href="core.html#accessfilename">.htaccess</a></code>文件中控制对服务器特定部分的访问。只要能在<a href="../env.html">环境变量</a>中捕获到主机名、IP地址或其他的客户端请求特征,就可以基于这些特征对访问进行控制。<code class="directive"><a href="#allow">Allow</a></code>和<code class="directive"><a href="#deny">Deny</a></code>指令用于指出允许哪些客户及不允许哪些客户访问服务器,而<code class="directive"><a href="#order">Order</a></code>指令设置默认的访问状态并配置<code class="directive"><a href="#allow">Allow</a></code>和<code class="directive"><a href="#deny">Deny</a></code>指令怎样相互作用。</p>
<p>基于主机的访问控制和基于口令的身份验证两套机制可以同时实现。在这种情况下,<code class="directive"><a href="../mod/core.html#satisfy">Satisfy</a></code>指令用来决定两套机制如何相互作用。</p>
<p>一般来说,访问控制指令适用于所有的访问方法(<code>GET</code>, <code>PUT</code>, <code>POST</code>等)。在多数情况下这是一个被期望的特性。但是,只限制某些方法而对其他方法不加限制也是可能的:通过把指令放到一个<code class="directive"><a href="../mod/core.html#limit"><Limit></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="Allow" id="Allow">Allow</a> <a name="allow" id="allow">指令</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> Allow 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><code class="directive">Allow</code>指令控制哪些主机可以访问服务器的该区域。可以根据主机名、IP地址、 IP地址范围或其他环境变量中捕获的客户端请求特性进行控制。</p>
<p>这个指令的第一个参数总是"<code>from</code>",随后的参数可以有三种不同形式:如果指定"<code>Allow from all</code>",则允许所有主机访问,按照下述<code class="directive"><a href="#deny">Deny</a></code>和<code class="directive"><a href="#order">Order</a></code>指令的配置。若要只允许特定的主机或主机群访问服务器,<em>host</em>可以用下面任何一种格式来指定:</p>
<dl>
<dt>一个(部分)域名</dt>
<dd>
<div class="example"><h3>示例:</h3><p><code>
Allow from apache.org<br />
Allow from .net example.edu
</code></p></div>
<p>主机名与给定字符串匹配或者以给定字符串结尾的主机允许访问。只有完整的名字组成部分才被匹配,因此上述例子将匹配<code>foo.apache.org</code>但不能匹配<code>fooapache.org</code> 。这样的配置将导致Apache不管<code class="directive"><a href="../mod/core.html#hostnamelookups">HostnameLookups</a></code>指令是如何设置的,对一个对客户IP地址都要执行两次DNS查询:一次正查询保证IP没有伪造,一次反查询保证主机名没有伪造。只有两次查询的结果都吻合,并且主机名能够被匹配,访问才被允许。</p></dd>
<dt>完整的IP地址</dt>
<dd>
<div class="example"><h3>示例:</h3><p><code>
Allow from 10.1.2.3<br />
Allow from 192.168.1.104 192.168.1.205
</code></p></div>
<p>允许拥有这些IP地址的主机进行访问。</p></dd>
<dt>部分IP地址</dt>
<dd>
<div class="example"><h3>示例:</h3><p><code>
Allow from 10.1<br />
Allow from 10 172.20 192.168.2
</code></p></div>
<p>IP地址的开始1到3个字节,用于子网限制。</p></dd>
<dt>网络/掩码对</dt>
<dd>
<div class="example"><h3>示例:</h3><p><code>
Allow from 10.1.0.0/255.255.0.0
</code></p></div>
<p>一个网络"a.b.c.d"和一个掩码"w.x.y.z",用于更精确的子网限制。</p></dd>
<dt>网络/nnn无类别域间路由规格(CIDR specification)</dt>
<dd>
<div class="example"><h3>示例:</h3><p><code>
Allow from 10.1.0.0/16
</code></p></div>
<p>同前一种情况相似,除了掩码由nnn个高位字节构成。</p></dd>
</dl>
<p>注意以上例子中的后三个匹配完全相同的一组主机。</p>
<p>IPv6地址和IPv6子网可以像下面这样指定:</p>
<div class="example"><p><code>
Allow from 2001:db8::a00:20ff:fea7:ccea<br />
Allow from 2001:db8::a00:20ff:fea7:ccea/10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -