1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5              This file is generated from xml source: DO NOT EDIT
6        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7      -->
8<title>mod_authz_host - Apache HTTP Server</title>
9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
12<script src="/style/scripts/prettify.js" type="text/javascript">
13</script>
14
15<link href="/images/favicon.ico" rel="shortcut icon" /></head>
16<body>
17<div id="page-header">
18<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
19<p class="apache">Apache HTTP Server Version 2.2</p>
20<img alt="" src="/images/feather.gif" /></div>
21<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
22<div id="path">
23<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.2</a> &gt; <a href="./">Modules</a></div>
24<div id="page-content">
25<div id="preamble"><h1>Apache Module mod_authz_host</h1>
26<div class="toplang">
27<p><span>Available Languages: </span><a href="/en/mod/mod_authz_host.html" title="English">&nbsp;en&nbsp;</a> |
28<a href="/fr/mod/mod_authz_host.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
29<a href="/ja/mod/mod_authz_host.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
30<a href="/ko/mod/mod_authz_host.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p>
31</div>
32<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Group authorizations based on host (name or IP
33address)</td></tr>
34<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
35<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>authz_host_module</td></tr>
36<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_authz_host.c</td></tr>
37<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 2.1 and later</td></tr></table>
38<h3>Summary</h3>
39
40    <p>The directives provided by <code class="module"><a href="/mod/mod_authz_host.html">mod_authz_host</a></code> are
41    used in <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code>,
42    <code class="directive"><a href="/mod/core.html#files">&lt;Files&gt;</a></code>, and
43    <code class="directive"><a href="/mod/core.html#location">&lt;Location&gt;</a></code> sections
44    as well as <code><a href="core.html#accessfilename">.htaccess</a>
45    </code> files to control access to particular parts of the server.
46    Access can be controlled based on the client hostname, IP address, or
47    other characteristics of the client request, as captured in <a href="/env.html">environment variables</a>. The <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives are used to
48    specify which clients are or are not allowed access to the server,
49    while the <code class="directive"><a href="#order">Order</a></code>
50    directive sets the default access state, and configures how the
51    <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives interact with each
52    other.</p>
53
54    <p>Both host-based access restrictions and password-based
55    authentication may be implemented simultaneously. In that case,
56    the <code class="directive"><a href="/mod/core.html#satisfy">Satisfy</a></code> directive is used
57    to determine how the two sets of restrictions interact.</p>
58
59    <p>In general, access restriction directives apply to all
60    access methods (<code>GET</code>, <code>PUT</code>,
61    <code>POST</code>, etc). This is the desired behavior in most
62    cases. However, it is possible to restrict some methods, while
63    leaving other methods unrestricted, by enclosing the directives
64    in a <code class="directive"><a href="/mod/core.html#limit">&lt;Limit&gt;</a></code> section.</p>
65</div>
66<div id="quickview"><h3 class="directives">Directives</h3>
67<ul id="toc">
68<li><img alt="" src="/images/down.gif" /> <a href="#allow">Allow</a></li>
69<li><img alt="" src="/images/down.gif" /> <a href="#deny">Deny</a></li>
70<li><img alt="" src="/images/down.gif" /> <a href="#order">Order</a></li>
71</ul>
72<h3>See also</h3>
73<ul class="seealso">
74<li><code class="directive"><a href="/mod/core.html#satisfy">Satisfy</a></code></li>
75<li><code class="directive"><a href="/mod/core.html#require">Require</a></code></li>
76</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
77
78<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
79<div class="directive-section"><h2><a name="Allow" id="Allow">Allow</a> <a name="allow" id="allow">Directive</a></h2>
80<table class="directive">
81<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls which hosts can access an area of the
82server</td></tr>
83<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> Allow from all|<var>host</var>|env=[!]<var>env-variable</var>
84[<var>host</var>|env=[!]<var>env-variable</var>] ...</code></td></tr>
85<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
86<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Limit</td></tr>
87<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
88<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_authz_host</td></tr>
89</table>
90    <p>The <code class="directive">Allow</code> directive affects which hosts can
91    access an area of the server. Access can be controlled by
92    hostname, IP address, IP address range, or by other
93    characteristics of the client request captured in environment
94    variables.</p>
95
96    <p>The first argument to this directive is always
97    <code>from</code>. The subsequent arguments can take three
98    different forms. If <code>Allow from all</code> is specified, then
99    all hosts are allowed access, subject to the configuration of the
100    <code class="directive"><a href="#deny">Deny</a></code> and <code class="directive"><a href="#order">Order</a></code> directives as discussed
101    below. To allow only particular hosts or groups of hosts to access
102    the server, the <em>host</em> can be specified in any of the
103    following formats:</p>
104
105    <dl>
106      <dt>A (partial) domain-name</dt>
107
108      <dd>
109      <div class="example"><h3>Example:</h3><p><code>
110        Allow from apache.org<br />
111        Allow from .net example.edu
112      </code></p></div>
113      <p>Hosts whose names match, or end in, this string are allowed
114      access. Only complete components are matched, so the above
115      example will match <code>foo.apache.org</code> but it will not
116      match <code>fooapache.org</code>. This configuration will cause
117      Apache to perform a double reverse DNS lookup on the client IP
118      address, regardless of the setting of the <code class="directive"><a href="/mod/core.html#hostnamelookups">HostnameLookups</a></code> directive.  It will do
119      a reverse DNS lookup on the IP address to find the associated
120      hostname, and then do a forward lookup on the hostname to assure
121      that it matches the original IP address.  Only if the forward
122      and reverse DNS are consistent and the hostname matches will
123      access be allowed.</p></dd>
124
125      <dt>A full IP address</dt>
126
127      <dd>
128      <div class="example"><h3>Example:</h3><p><code>
129        Allow from 10.1.2.3<br />
130        Allow from 192.168.1.104 192.168.1.205
131      </code></p></div>
132      <p>An IP address of a host allowed access</p></dd>
133
134      <dt>A partial IP address</dt>
135
136      <dd>
137      <div class="example"><h3>Example:</h3><p><code>
138        Allow from 10.1<br />
139        Allow from 10 172.20 192.168.2
140      </code></p></div>
141      <p>The first 1 to 3 bytes of an IP address, for subnet
142      restriction.</p></dd>
143
144      <dt>A network/netmask pair</dt>
145
146      <dd>
147      <div class="example"><h3>Example:</h3><p><code>
148        Allow from 10.1.0.0/255.255.0.0
149      </code></p></div>
150      <p>A network a.b.c.d, and a netmask w.x.y.z. For more
151      fine-grained subnet restriction.</p></dd>
152
153      <dt>A network/nnn CIDR specification</dt>
154
155      <dd>
156      <div class="example"><h3>Example:</h3><p><code>
157        Allow from 10.1.0.0/16
158      </code></p></div>
159      <p>Similar to the previous case, except the netmask consists of
160      nnn high-order 1 bits.</p></dd>
161    </dl>
162
163    <p>Note that the last three examples above match exactly the
164    same set of hosts.</p>
165
166    <p>IPv6 addresses and IPv6 subnets can be specified as shown
167    below:</p>
168
169    <div class="example"><p><code>
170       Allow from 2001:db8::a00:20ff:fea7:ccea<br />
171       Allow from 2001:db8::a00:20ff:fea7:ccea/10
172    </code></p></div>
173
174    <p>The third format of the arguments to the
175    <code class="directive">Allow</code> directive allows access to the server
176    to be controlled based on the existence of an <a href="/env.html">environment variable</a>. When <code>Allow from
177    env=<var>env-variable</var></code> is specified, then the request is
178    allowed access if the environment variable <var>env-variable</var>
179    exists. When <code>Allow from env=!<var>env-variable</var></code> is 
180    specified, then the request is allowed access if the environment 
181    variable <var>env-variable</var> doesn't exist.
182    The server provides the ability to set environment
183    variables in a flexible way based on characteristics of the client
184    request using the directives provided by
185    <code class="module"><a href="/mod/mod_setenvif.html">mod_setenvif</a></code>. Therefore, this directive can be
186    used to allow access based on such factors as the clients
187    <code>User-Agent</code> (browser type), <code>Referer</code>, or
188    other HTTP request header fields.</p>
189
190    <div class="example"><h3>Example:</h3><p><code>
191      SetEnvIf User-Agent ^KnockKnock/2\.0 let_me_in<br />
192      &lt;Directory /docroot&gt;<br />
193      <span class="indent">
194        Order Deny,Allow<br />
195        Deny from all<br />
196        Allow from env=let_me_in<br />
197      </span>
198      &lt;/Directory&gt;
199    </code></p></div>
200
201    <p>In this case, browsers with a user-agent string beginning
202    with <code>KnockKnock/2.0</code> will be allowed access, and all
203    others will be denied.</p>
204
205</div>
206<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
207<div class="directive-section"><h2><a name="Deny" id="Deny">Deny</a> <a name="deny" id="deny">Directive</a></h2>
208<table class="directive">
209<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls which hosts are denied access to the
210server</td></tr>
211<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> Deny from all|<var>host</var>|env=[!]<var>env-variable</var>
212[<var>host</var>|env=[!]<var>env-variable</var>] ...</code></td></tr>
213<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
214<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Limit</td></tr>
215<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
216<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_authz_host</td></tr>
217</table>
218    <p>This directive allows access to the server to be restricted
219    based on hostname, IP address, or environment variables. The
220    arguments for the <code class="directive">Deny</code> directive are
221    identical to the arguments for the <code class="directive"><a href="#allow">Allow</a></code> directive.</p>
222
223</div>
224<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
225<div class="directive-section"><h2><a name="Order" id="Order">Order</a> <a name="order" id="order">Directive</a></h2>
226<table class="directive">
227<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls the default access state and the order in which
228<code class="directive">Allow</code> and <code class="directive">Deny</code> are
229evaluated.</td></tr>
230<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> Order <var>ordering</var></code></td></tr>
231<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>Order Deny,Allow</code></td></tr>
232<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
233<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Limit</td></tr>
234<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
235<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_authz_host</td></tr>
236</table>
237
238    <p>The <code class="directive">Order</code> directive, along with the
239    <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives, controls a
240    three-pass access control system. The first pass processes either
241    all <code class="directive"><a href="#allow">Allow</a></code> or all
242    <code class="directive"><a href="#deny">Deny</a></code> directives, as
243    specified by the <code class="directive">Order</code> directive. The second
244    pass parses the rest of the directives (<code class="directive"><a href="#deny">Deny</a></code> or <code class="directive"><a href="#allow">Allow</a></code>). The third pass applies
245    to all requests which do not match either of the first two.</p>
246
247    <p>Note that all <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives are processed,
248    unlike a typical firewall, where only the first match is used. The
249    last match is effective (also unlike a typical firewall).
250    Additionally, the order in which lines appear in the configuration
251    files is not significant -- all <code class="directive"><a href="#allow">Allow</a></code> lines are processed as one
252    group, all <code class="directive"><a href="#deny">Deny</a></code> lines
253    are considered as another, and the default state is considered by
254    itself.</p>
255
256    <p><em>Ordering</em> is one of:</p>
257
258    <dl>
259      <dt><code>Allow,Deny</code></dt>
260
261      <dd>First, all <code class="directive"><a href="#allow">Allow</a></code> directives are
262      evaluated; at least one must match, or the request is rejected.
263      Next, all <code class="directive"><a href="#deny">Deny</a></code>
264      directives are evaluated. If any matches, the request is rejected.
265      Last, any requests which do not match an <code class="directive"><a href="#allow">Allow</a></code> or a <code class="directive"><a href="#deny">Deny</a></code> directive are denied by
266      default.</dd>
267
268      <dt><code>Deny,Allow</code></dt>
269
270      <dd>First, all <code class="directive"><a href="#deny">Deny</a></code>
271      directives are evaluated; if any match, the request is denied
272      <strong>unless</strong> it also matches an <code class="directive"><a href="#allow">Allow</a></code> directive. Any requests
273      which do not match any <code class="directive"><a href="#allow">Allow</a></code> or <code class="directive"><a href="#deny">Deny</a></code> directives are
274      permitted.</dd>
275
276      <dt><code>Mutual-failure</code></dt>
277
278      <dd>This order has the same effect as <code>Order
279      Allow,Deny</code> and is deprecated in its favor.</dd>
280    </dl>
281
282    <p>Keywords may only be separated by a comma; <em>no whitespace</em>
283    is allowed between them.</p>
284
285    <table class="bordered">
286      <tr>
287        <th>Match</th>
288        <th>Allow,Deny result</th>
289        <th>Deny,Allow result</th>
290      </tr><tr>
291        <th>Match Allow only</th>
292        <td>Request allowed</td>
293        <td>Request allowed</td>
294      </tr><tr>
295        <th>Match Deny only</th>
296        <td>Request denied</td>
297        <td>Request denied</td>
298      </tr><tr>
299        <th>No match</th>
300        <td>Default to second directive: Denied</td>
301        <td>Default to second directive: Allowed</td>
302      </tr><tr>
303        <th>Match both Allow &amp; Deny</th>
304        <td>Final match controls: Denied</td>
305        <td>Final match controls: Allowed</td>
306      </tr>
307    </table>
308
309    <p>In the following example, all hosts in the apache.org domain
310    are allowed access; all other hosts are denied access.</p>
311
312    <div class="example"><p><code>
313      Order Deny,Allow<br />
314      Deny from all<br />
315      Allow from apache.org
316    </code></p></div>
317
318    <p>In the next example, all hosts in the apache.org domain are
319    allowed access, except for the hosts which are in the foo.apache.org
320    subdomain, who are denied access. All hosts not in the apache.org
321    domain are denied access because the default state is to <code class="directive"><a href="#deny">Deny</a></code> access to the server.</p>
322
323    <div class="example"><p><code>
324      Order Allow,Deny<br />
325      Allow from apache.org<br />
326      Deny from foo.apache.org
327    </code></p></div>
328
329    <p>On the other hand, if the <code class="directive">Order</code> in the
330    last example is changed to <code>Deny,Allow</code>, all hosts will
331    be allowed access. This happens because, regardless of the actual
332    ordering of the directives in the configuration file, the
333    <code>Allow from apache.org</code> will be evaluated last and will
334    override the <code>Deny from foo.apache.org</code>. All hosts not in
335    the <code>apache.org</code> domain will also be allowed access
336    because the default state is <code class="directive"><a href="#allow">Allow</a></code>.</p>
337
338    <p>The presence of an <code class="directive">Order</code> directive can
339    affect access to a part of the server even in the absence of
340    accompanying <code class="directive"><a href="#allow">Allow</a></code>
341    and <code class="directive"><a href="#deny">Deny</a></code> directives
342    because of its effect on the default access state. For example,</p>
343
344    <div class="example"><p><code>
345      &lt;Directory /www&gt;<br />
346      <span class="indent">
347        Order Allow,Deny<br />
348      </span>
349      &lt;/Directory&gt;
350    </code></p></div>
351
352    <p>will Deny all access to the <code>/www</code> directory
353    because the default access state is set to
354    <code class="directive"><a href="#deny">Deny</a></code>.</p>
355
356    <p>The <code class="directive">Order</code> directive controls the order of
357    access directive processing only within each phase of the server's
358    configuration processing. This implies, for example, that an
359    <code class="directive"><a href="#allow">Allow</a></code> or <code class="directive"><a href="#deny">Deny</a></code> directive occurring in a
360    <code class="directive"><a href="/mod/core.html#location">&lt;Location&gt;</a></code> section
361    will always be evaluated after an <code class="directive"><a href="#allow">Allow</a></code> or <code class="directive"><a href="#deny">Deny</a></code> directive occurring in a
362    <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code>
363    section or <code>.htaccess</code> file, regardless of the setting of
364    the <code class="directive">Order</code> directive. For details on the
365    merging of configuration sections, see the documentation on <a href="/sections.html">How Directory, Location and Files sections
366    work</a>.</p>
367
368</div>
369</div>
370<div class="bottomlang">
371<p><span>Available Languages: </span><a href="/en/mod/mod_authz_host.html" title="English">&nbsp;en&nbsp;</a> |
372<a href="/fr/mod/mod_authz_host.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
373<a href="/ja/mod/mod_authz_host.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
374<a href="/ko/mod/mod_authz_host.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p>
375</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
376<script type="text/javascript"><!--//--><![CDATA[//><!--
377var comments_shortname = 'httpd';
378var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html';
379(function(w, d) {
380    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
381        d.write('<div id="comments_thread"><\/div>');
382        var s = d.createElement('script');
383        s.type = 'text/javascript';
384        s.async = true;
385        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
386        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
387    }
388    else { 
389        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
390    }
391})(window, document);
392//--><!]]></script></div><div id="footer">
393<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
394<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
395if (typeof(prettyPrint) !== 'undefined') {
396    prettyPrint();
397}
398//--><!]]></script>
399</body></html>