summaryrefslogtreecommitdiff
path: root/htdocs/manual/mod/mod_access.html.en
blob: 1df0e5aa5b316afb5fb0e1f89b4e6e3e9c015099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="generator" content="HTML Tidy, see www.w3.org" />

    <title>Apache module mod_access</title>

<style>
.obsolete
{
  margin: 0;
  padding: 8px 10px;
  padding-left: 50px;
  padding-bottom: 10px;
  line-height: 1.4em;
  background: #f99 url(../images/warning.png) no-repeat 0px 0px;
}

.currentdocs
{
    background: #f99;
}

</style>

  </head>
  <!-- Background white, links blue (unvisited), navy (visited), red (active) -->

  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
  vlink="#000080" alink="#FF0000">


    <div align="CENTER">
      <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" />

      <h3>Apache HTTP Server Version 1.3</h3>
        <div class="obsolete"><p>You are looking at the documentation for the 
        1.3 version of the Apache HTTP Server, which is no longer
        maintained, and has been declared "end of life". If you are in
        fact still using the 1.3 version, please consider upgrading.
        The current version of the server is <a 
        href="http://httpd.apache.org/docs/2.2/">2.2</a>.

        In 2.2, the equivalent of this module is now named 
        <a
        href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html"
        >mod_authz_host</a>.</p> 

        </div>

    </div>

    <h1 align="center">Module mod_access</h1>

    <p>This module provides access control based on client
    hostname, IP address, or other characteristics of the client
    request.</p>

    <p><a href="module-dict.html#Status"
    rel="Help"><strong>Status:</strong></a> Base<br />
     <a href="module-dict.html#SourceFile"
    rel="Help"><strong>Source File:</strong></a> mod_access.c<br />
     <a href="module-dict.html#ModuleIdentifier"
    rel="Help"><strong>Module Identifier:</strong></a>
    access_module</p>

    <h2>Summary</h2>

    <p>The directives provided by mod_access are used in <code><a
    href="core.html#directory">&lt;Directory&gt;</a>, <a
    href="core.html#files">&lt;Files&gt;</a>,</code> and <code><a
    href="core.html#location">&lt;Location&gt;</a></code> sections
    as well as <code><a
    href="core.html#accessfilename">.htaccess</a></code> files to
    control access to particular parts of the server. Access can be
    controlled based on the client hostname, IP address, or other
    characteristics of the client request, as captured in <a
    href="../env.html">environment variables</a>. The
    <code>Allow</code> and <code>Deny</code> directives are used to
    specify which clients are or are not allowed access to the
    server, while the <code>Order</code> directive sets the default
    access state, and configures how the <code>Allow</code> and
    <code>Deny</code> directives interact with each other.</p>

    <p>Both host-based access restrictions and password-based
    authentication may be implemented simultaneously. In that case,
    the <a href="core.html#satisfy">Satisfy</a> directive is used
    to determine how the two sets of restrictions interact.</p>

    <p>In general, access restriction directives apply to all
    access methods (<code>GET</code>, <code>PUT</code>,
    <code>POST</code>, etc). This is the desired behavior in most
    cases. However, it is possible to restrict some methods, while
    leaving other methods unrestricted, by enclosing the directives
    in a <a href="core.html#limit">&lt;Limit&gt;</a> section.</p>

    <h2>Directives</h2>

    <ul>
      <li><a href="#allow">Allow</a></li>

      <li><a href="#deny">Deny</a></li>

      <li><a href="#order">Order</a></li>
    </ul>

    <p>See also <a href="core.html#satisfy">Satisfy</a> and <a
    href="core.html#require">Require</a>.</p>
    <hr />

    <h2><a id="allow" name="allow">Allow</a> <a id="allowfromenv"
    name="allowfromenv">directive</a></h2>

    <p>
     <a href="directive-dict.html#Syntax"
    rel="Help"><strong>Syntax:</strong></a> Allow from
    all|<em>host</em>|env=<em>env-variable</em>
    [<em>host</em>|env=<em>env-variable</em>] ...<br />
     <a href="directive-dict.html#Context"
    rel="Help"><strong>Context:</strong></a> directory,
    .htaccess<br />
     <a href="directive-dict.html#Override"
    rel="Help"><strong>Override:</strong></a> Limit<br />
     <a href="directive-dict.html#Status"
    rel="Help"><strong>Status:</strong></a> Base<br />
     <a href="directive-dict.html#Module"
    rel="Help"><strong>Module:</strong></a> mod_access</p>

    <p class="currentdocs"><strong>Current documentation for this directive may be found <a
    href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow">here</a></strong></p>
 
    <p>The <code>Allow</code> directive affects which hosts can
    access an area of the server. Access can be controlled by
    hostname, IP address, IP address range, or other
    characteristics of the client request captured in environment
    variables.</p>

    <p>The first argument to this directive is always
    <code>from</code>. The subsequent arguments can take three
    different forms. If <code>Allow from all</code> is specified,
    then all hosts are allowed access, subject to the configuration
    of the <code>Deny</code> and <code>Order</code> directives as
    discussed below. To allow only particular hosts or groups of
    hosts to access the server, the <em>host</em> can be specified
    in any of the following formats:</p>

    <dl>
      <dt>A (partial) domain-name</dt>

      <dd>Example: <code>Allow from apache.org</code><br />
       Hosts whose names match, or end in, this string are allowed
      access. Only complete components are matched, so the above
      example will match <code>foo.apache.org</code> but it will
      not match <code>fooapache.org</code>. This configuration will
      cause the server to perform a double reverse DNS lookup on the
      client IP address, regardless of the setting of the <a
      href="core.html#hostnamelookups">HostnameLookups</a>
      directive.  It will do a reverse DNS lookup on the IP address to
      find the associated hostname, and then do a forward lookup on
      the hostname to assure that it matches the original IP address.
      Only if the forward and reverse DNS are consistent and the
      hostname matches will access be allowed.</dd>

      <dt>A full IP address</dt>

      <dd>Example: <code>Allow from 10.1.2.3</code><br />
       An IP address of a host allowed access</dd>

      <dt>A partial IP address</dt>

      <dd>Example: <code>Allow from 10.1</code><br />
       The first 1 to 3 bytes of an IP address, for subnet
      restriction.</dd>

      <dt>A network/netmask pair</dt>

      <dd>Example: <code>Allow from
      10.1.0.0/255.255.0.0</code><br />
       A network a.b.c.d, and a netmask w.x.y.z. For more
      fine-grained subnet restriction. (Apache 1.3 and later)</dd>

      <dt>A network/nnn CIDR specification</dt>

      <dd>Example: <code>Allow from 10.1.0.0/16</code><br />
       Similar to the previous case, except the netmask consists of
      nnn high-order 1 bits. (Apache 1.3 and later)</dd>
    </dl>

    <p>Note that the last three examples above match exactly the
    same set of hosts.</p>

    <p>The third format of the arguments to the <code>Allow</code>
    directive allows access to the server to be controlled based on
    the existence of an <a href="../env.html">environment
    variable</a>. When <code>Allow from
    env=</code><em>env-variable</em> is specified, then the request
    is allowed access if the environment variable
    <em>env-variable</em> exists. The server provides the ability
    to set environment variables in a flexible way based on
    characteristics of the client request using the directives
    provided by <a href="mod_setenvif.html">mod_setenvif</a>.
    Therefore, this directive can be used to allow access based on
    such factors as the clients <code>User-Agent</code> (browser
    type), <code>Referer</code>, or other HTTP request header
    fields.</p>

    <p>Example:</p>

    <blockquote>
<pre>
SetEnvIf User-Agent ^KnockKnock/2\.0 let_me_in
&lt;Directory /docroot&gt;
    Order Deny,Allow
    Deny from all
    Allow from env=let_me_in
&lt;/Directory&gt;
</pre>
    </blockquote>

    <p>In this case, browsers with a user-agent string beginning
    with <tt>KnockKnock/2.0</tt> will be allowed access, and all
    others will be denied.</p>

    <p>See also <a href="#deny">Deny</a>, <a
    href="#order">Order</a> and <a
    href="mod_setenvif.html#setenvif">SetEnvIf</a>.</p>
    <hr />

    <h2><a id="deny" name="deny">Deny</a> <a id="denyfromenv"
    name="denyfromenv">directive</a></h2>

    <p>
     <a href="directive-dict.html#Syntax"
    rel="Help"><strong>Syntax:</strong></a> Deny from
    all|<em>host</em>|env=<em>env-variable</em>
    [<em>host</em>|env=<em>env-variable</em>] ...<br />
     <a href="directive-dict.html#Context"
    rel="Help"><strong>Context:</strong></a> directory,
    .htaccess<br />
     <a href="directive-dict.html#Override"
    rel="Help"><strong>Override:</strong></a> Limit<br />
     <a href="directive-dict.html#Status"
    rel="Help"><strong>Status:</strong></a> Base<br />
     <a href="directive-dict.html#Module"
    rel="Help"><strong>Module:</strong></a> mod_access</p>

    <p class="currentdocs"><strong>Current documentation for this directive may be found <a
    href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#deny">here</a></strong></p>
 
    <p>This directive allows access to the server to be restricted
    based on hostname, IP address, or environment variables. The
    arguments for the <code>Deny</code> directive are identical to
    the arguments for the <a href="#allow">Allow</a> directive.</p>

    <p>See also <a href="#allow">Allow</a>, <a
    href="#order">Order</a> and <a
    href="mod_setenvif.html#setenvif">SetEnvIf</a>.</p>
    <hr />

    <h2><a id="order" name="order">Order directive</a></h2>

    <p>
     <a href="directive-dict.html#Syntax"
    rel="Help"><strong>Syntax:</strong></a> Order
    <em>ordering</em><br />
     <a href="directive-dict.html#Default"
    rel="Help"><strong>Default:</strong></a> <code>Order
    Deny,Allow</code><br />
     <a href="directive-dict.html#Context"
    rel="Help"><strong>Context:</strong></a> directory,
    .htaccess<br />
     <a href="directive-dict.html#Override"
    rel="Help"><strong>Override:</strong></a> Limit<br />
     <a href="directive-dict.html#Status"
    rel="Help"><strong>Status:</strong></a> Base<br />
     <a href="directive-dict.html#Module"
    rel="Help"><strong>Module:</strong></a> mod_access</p>

    <p class="currentdocs"><strong>Current documentation for this directive may be found <a
    href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order">here</a></strong></p>
 
    <p>The <code>Order</code> directive, along with the
    <code>Allow</code> and <code>Deny</code> directives, controls a
    three-pass access control system. The first pass processes either
    all <code>Allow</code> or all <code>Deny</code> directives, as
    specified by the <code>Order</code> directive. The second pass
    parses the rest of the directives (<code>Deny</code> or
    <code>Allow</code>). The third pass applies to all requests which do
    not match either of the first two.</p>

    <p>Note that all <code>Allow</code> and <code>Deny</code> directives
    are processed, unlike a typical firewall, where only the first match
    is used. The last match is effective (also unlike a typical
    firewall). Additionally, the order in which lines appear in the
    configuration files is not significant -- all <code>Allow</code>
    lines are processed as one group, all <code>Deny</code> lines are
    considered as another, and the default state is considered by
    itself.</p>

    <p><em>Ordering</em> is one of:</p>

    <dl>
      <dt><code>Allow,Deny</code></dt>

      <dd>First, all <code>Allow</code> directives are evaluated; at
      least one must match, or the request is rejected. Next, all
      <code>Deny</code> directives are evaluated. If any matches, the
      request is rejected. Last, any requests which do not match an
      <code>Allow</code> or a <code>Deny</code> directive are denied by
      default.</dd>

      <dt><code>Deny,Allow</code></dt>

      <dd>First, all <code>Deny</code> directives are evaluated; if any
      match, the request is denied <strong>unless</strong> it also
      matches an <code>Allow</code> directive. Any requests which do not
      match any <code>Allow</code> or <code>Deny</code> directives are
      permitted.</dd>

      <dt><code>Mutual-failure</code></dt>

      <dd>This order has the same effect as <code>Order
      Allow,Deny</code> and is deprecated in its favor.</dd>
    </dl>

    <p>Keywords may only be separated by a comma; no whitespace is
    allowed between them.</p>

    <table border="1">
        <tr>
            <th>Match</th>
            <th>Allow,Deny result</th>
            <th>Deny,Allow result</th>
        </tr><tr>
            <th>Match Allow only</th>
            <td>Request allowed</td>
            <td>Request allowed</td>
        </tr><tr>
            <th>Match Deny only</th>
            <td>Request denied</td>
            <td>Request denied</td>
        </tr><tr>
            <th>No match</th>
            <td>Default to second directive: Denied</td>
            <td>Default to second directive: Allowed</td>
        </tr><tr>
            <th>Match both Allow &amp; Deny</th>
            <td>Final match controls: Denied</td>
            <td>Final match controls: Allowed</td>
        </tr>
    </table>

    <p>In the following example, all hosts in the apache.org domain
    are allowed access; all other hosts are denied access.</p>

    <blockquote>
      <code>Order Deny,Allow<br />
       Deny from all<br />
       Allow from apache.org<br />
      </code>
    </blockquote>

    <p>In the next example, all hosts in the apache.org domain are
    allowed access, except for the hosts which are in the
    foo.apache.org subdomain, who are denied access. All hosts not
    in the apache.org domain are denied access because the default
    state is to <code>Deny</code> access to the server.</p>

    <blockquote>
      <code>Order Allow,Deny<br />
       Allow from apache.org<br />
       Deny from foo.apache.org<br />
      </code>
    </blockquote>

    <p>On the other hand, if the <code>Order</code> in the last
    example is changed to <code>Deny,Allow</code>, all hosts will
    be allowed access. This happens because, regardless of the
    actual ordering of the directives in the configuration file,
    the <code>Allow from apache.org</code> will be evaluated last
    and will override the <code>Deny from foo.apache.org</code>.
    All hosts not in the <code>apache.org</code> domain will also
    be allowed access because the default state is
    <code>Allow</code>.</p>

    <p>The presence of an <code>Order</code> directive can affect
    access to a part of the server even in the absence of
    accompanying <code>Allow</code> and <code>Deny</code>
    directives because of its effect on the default access state.
    For example,</p>

    <blockquote>
      <code>&lt;Directory /www&gt;<br />
       &nbsp;&nbsp;Order Allow,Deny<br />
       &lt;/Directory&gt;</code>
    </blockquote>

    <p>will Deny all access to the <code>/www</code> directory
    because the default access state is set to
    <code>Deny</code>.</p>

    <p>The <code>Order</code> directive controls the order of
    access directive processing only within each phase of the
    server's configuration processing. This implies, for example,
    that an <code>Allow</code> or <code>Deny</code> directive
    occurring in a &lt;Location&gt; section will always be
    evaluated after an <code>Allow</code> or <code>Deny</code>
    directive occurring in a &lt;Directory&gt; section or
    <code>.htaccess</code> file, regardless of the setting of the
    <code>Order</code> directive. For details on the merging of
    configuration sections, see the documentation on <a
    href="../sections.html">How Directory, Location and Files
    sections work</a>.</p>

    <p>See also: <a href="#deny">Deny</a> and <a
    href="#allow">Allow</a>. <!--#include virtual="footer.html" -->
    </p>
  </body>
</html>