]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_access.html
0c3bb9178c2edd5f374f3419384cfdf7bf173afc
[apache] / docs / manual / mod / mod_access.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Apache module mod_access</TITLE>
5 </HEAD>
6
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
8 <BODY
9  BGCOLOR="#FFFFFF"
10  TEXT="#000000"
11  LINK="#0000FF"
12  VLINK="#000080"
13  ALINK="#FF0000"
14 >
15 <!--#include virtual="header.html" -->
16
17 <H1 ALIGN="CENTER">Module mod_access</H1>
18 <P>
19 This module is contained in the <CODE>mod_access.c</CODE> file, and
20 is compiled in by default. It provides access control based on client
21 hostname or IP address.
22 </P>
23
24 <UL>
25 <LI><A HREF="#allow">allow</A>
26 <LI><A HREF="#allowfromenv">allow from env=</A>
27 <LI><A HREF="#deny">deny</A>
28 <LI><A HREF="#denyfromenv">deny from env=</A>
29 <LI><A HREF="#order">order</A>
30 </UL>
31 <HR>
32
33
34 <H2><A NAME="allow">allow directive</A></H2>
35 <P>
36 <!--%plaintext &lt;?INDEX {\tt allow} directive&gt; -->
37 <A
38  HREF="directive-dict.html#Syntax"
39  REL="Help"
40 ><STRONG>Syntax:</STRONG></A> allow from <EM>host host ...</EM><BR>
41 <A
42  HREF="directive-dict.html#Context"
43  REL="Help"
44 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
45 <A
46  HREF="directive-dict.html#Override"
47  REL="Help"
48 ><STRONG>Override:</STRONG></A> Limit<BR>
49 <A
50  HREF="directive-dict.html#Status"
51  REL="Help"
52 ><STRONG>Status:</STRONG></A> Base<BR>
53 <A
54  HREF="directive-dict.html#Module"
55  REL="Help"
56 ><STRONG>Module:</STRONG></A> mod_access
57 </P>
58 <P>
59 The allow directive affects which hosts can access a given directory.
60 <EM>Host</EM> is one of the following:
61 </P>
62 <DL>
63 <DT><CODE>all</CODE>
64 <DD>All hosts are allowed access
65 <DT>A (partial) domain-name
66 <DD>Hosts whose names match, or end in, this string are allowed access.
67 <DT>A full IP address
68 <DD>An IP address of a host allowed access
69 <DT>A partial IP address
70 <DD>The first 1 to 3 bytes of an IP address, for subnet restriction.
71 <DT>A network/netmask pair (<STRONG>Apache 1.3 and later</STRONG>)
72 <DD>A network a.b.c.d, and a netmask w.x.y.z.  For more fine-grained subnet
73     restriction.  (<EM>i.e.</EM>, 10.1.0.0/255.255.0.0)
74 <DT>A network/nnn CIDR specification (<STRONG>Apache 1.3 and later</STRONG>)
75 <DD>Similar to the previous case, except the netmask consists of nnn 
76     high-order 1 bits.  (<EM>i.e.</EM>, 10.1.0.0/16 is the same as 10.1.0.0/255.255.0.0)
77 </DL>
78 <P>
79 Example:
80 </P>
81 <BLOCKQUOTE><CODE>allow from .ncsa.uiuc.edu</CODE></BLOCKQUOTE>
82 <P>
83 All hosts in the specified domain are allowed access.
84 </P>
85 <P>
86 Note that this compares whole components; <CODE>bar.edu</CODE>
87 would not match <CODE>foobar.edu</CODE>.
88 </P>
89 <P>
90 See also <A HREF="#deny">deny</A>, <A HREF="#order">order</A>, and
91 <A HREF="mod_browser.html#browsermatch">BrowserMatch</A>.
92 </P>
93
94 <P>
95 <A NAME="allowfromenv"><STRONG>Syntax:</STRONG> allow from
96  env=<EM>variablename</EM></A><BR>
97 <A
98  HREF="directive-dict.html#Context"
99  REL="Help"
100 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
101 <A
102  HREF="directive-dict.html#Override"
103  REL="Help"
104 ><STRONG>Override:</STRONG></A> Limit<BR>
105 <A
106  HREF="directive-dict.html#Status"
107  REL="Help"
108 ><STRONG>Status:</STRONG></A> Base<BR>
109 <A
110  HREF="directive-dict.html#Module"
111  REL="Help"
112 ><STRONG>Module:</STRONG></A> mod_access<BR>
113 <A
114  HREF="directive-dict.html#Compatibility"
115  REL="Help"
116 ><STRONG>Compatibility:</STRONG></A> Apache 1.2 and above
117 </P>
118 <P>
119 The allow from env directive controls access to a directory by the
120 existence (or non-existence) of an environment variable.
121 </P>
122 <P>
123 Example:
124 </P>
125 <BLOCKQUOTE><PRE>
126 BrowserMatch ^KnockKnock/2.0 let_me_in
127 &lt;Directory /docroot&gt;
128     order deny,allow
129     deny from all
130     allow from env=let_me_in
131 &lt;/Directory&gt;
132 </PRE></BLOCKQUOTE>
133 In this case browsers with the user-agent string <TT>KnockKnock/2.0</TT> will
134 be allowed access, and all others will be denied.
135 <P>
136 See also <A HREF="#denyfromenv">deny from env</A>
137 and <A HREF="#order">order</A>.
138 </P>
139 <HR>
140
141 <H2><A NAME="deny">deny directive</A></H2>
142 <P>
143 <!--%plaintext &lt;?INDEX {\tt deny} directive&gt; -->
144 <A
145  HREF="directive-dict.html#Syntax"
146  REL="Help"
147 ><STRONG>Syntax:</STRONG></A> deny from <EM>host host ...</EM><BR>
148 <A
149  HREF="directive-dict.html#Context"
150  REL="Help"
151 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
152 <A
153  HREF="directive-dict.html#Override"
154  REL="Help"
155 ><STRONG>Override:</STRONG></A> Limit<BR>
156 <A
157  HREF="directive-dict.html#Status"
158  REL="Help"
159 ><STRONG>Status:</STRONG></A> Base<BR>
160 <A
161  HREF="directive-dict.html#Module"
162  REL="Help"
163 ><STRONG>Module:</STRONG></A> mod_access
164 </P>
165 <P>
166 The deny directive affects which hosts can access a given directory.
167 <EM>Host</EM> is one of the following:
168 </P>
169 <DL>
170 <DT><CODE>all</CODE>
171 <DD>all hosts are denied access
172 <DT>A (partial) domain-name
173 <DD>host whose name is, or ends in, this string are denied access.
174 <DT>A full IP address
175 <DD>An IP address of a host denied access
176 <DT>A partial IP address
177 <DD>The first 1 to 3 bytes of an IP address, for subnet restriction.
178 <DT>A network/netmask pair (<STRONG>Apache 1.3 and later</STRONG>)
179 <DD>A network a.b.c.d, and a netmask w.x.y.z.  For more fine-grained subnet
180     restriction.  (<EM>i.e.</EM>, 10.1.0.0/255.255.0.0)
181 <DT>A network/nnn CIDR specification (<STRONG>Apache 1.3 and later</STRONG>)
182 <DD>Similar to the previous case, except the netmask consists of nnn 
183     high-order 1 bits.  (<EM>i.e.</EM>, 10.1.0.0/16 is the same as 10.1.0.0/255.255.0.0)
184 </DL>
185 <P>
186 Example:
187 </P>
188 <BLOCKQUOTE><CODE>deny from 16</CODE></BLOCKQUOTE>
189 <P>
190 All hosts in the specified network are denied access.
191 </P>
192 <P>
193 Note that this compares whole components; <CODE>bar.edu</CODE>
194 would not match <CODE>foobar.edu</CODE>.
195 </P>
196 <P>
197 See also <A HREF="#allow">allow</A> and <A HREF="#order">order</A>.
198 </P>
199
200 <P>
201 <A NAME="denyfromenv"><STRONG>Syntax:</STRONG> deny from
202  env=<EM>variablename</EM></A><BR>
203 <A
204  HREF="directive-dict.html#Context"
205  REL="Help"
206 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
207 <A
208  HREF="directive-dict.html#Override"
209  REL="Help"
210 ><STRONG>Override:</STRONG></A> Limit<BR>
211 <A
212  HREF="directive-dict.html#Status"
213  REL="Help"
214 ><STRONG>Status:</STRONG></A> Base<BR>
215 <A
216  HREF="directive-dict.html#Module"
217  REL="Help"
218 ><STRONG>Module:</STRONG></A> mod_access<BR>
219 <A
220  HREF="directive-dict.html#Compatibility"
221  REL="Help"
222 ><STRONG>Compatibility:</STRONG></A> Apache 1.2 and above
223 </P>
224 <P>
225 The deny from env directive controls access to a directory by the
226 existence (or non-existence) of an environment variable.
227 </P>
228 <P>
229 Example:
230 </P>
231 <BLOCKQUOTE><PRE>
232 BrowserMatch ^BadRobot/0.9 go_away
233 &lt;Directory /docroot&gt;
234     order allow,deny
235     allow from all
236     deny from env=go_away
237 &lt;/Directory&gt;
238 </PRE></BLOCKQUOTE>
239 In this case browsers with the user-agent string <TT>BadRobot/0.9</TT> will
240 be denied access, and all others will be allowed.
241
242 <P>
243 See also <A HREF="#allowfromenv">allow from env</A>
244 and <A HREF="#order">order</A>.
245 </P>
246 <HR>
247
248 <H2><A NAME="order">order directive</A></H2>
249 <P>
250 <!--%plaintext &lt;?INDEX {\tt order} directive&gt; -->
251 <A
252  HREF="directive-dict.html#Syntax"
253  REL="Help"
254 ><STRONG>Syntax:</STRONG></A> order <EM>ordering</EM><BR>
255 <A
256  HREF="directive-dict.html#Default"
257  REL="Help"
258 ><STRONG>Default:</STRONG></A> <CODE>order deny,allow</CODE><BR>
259 <A
260  HREF="directive-dict.html#Context"
261  REL="Help"
262 ><STRONG>Context:</STRONG></A> directory, .htaccess<BR>
263 <A
264  HREF="directive-dict.html#Override"
265  REL="Help"
266 ><STRONG>Override:</STRONG></A> Limit<BR>
267 <A
268  HREF="directive-dict.html#Status"
269  REL="Help"
270 ><STRONG>Status:</STRONG></A> Base<BR>
271 <A
272  HREF="directive-dict.html#Module"
273  REL="Help"
274 ><STRONG>Module:</STRONG></A> mod_access
275 </P>
276 <P>
277 The order directive controls the order in which <A HREF="#allow">allow</A> and
278 <A HREF="#deny">deny</A> directives are evaluated. <EM>Ordering</EM> is one
279 of
280 </P>
281 <DL>
282 <DT>deny,allow
283 <DD>the deny directives are evaluated before the allow directives.  (The
284 initial state is OK.)
285 <DT>allow,deny
286 <DD>the allow directives are evaluated before the deny directives.  (The
287 initial state is FORBIDDEN.)
288 <DT>mutual-failure
289 <DD>Only those hosts which appear on the allow list and do not appear
290 on the deny list are granted access.  (The initial state is irrelevant.)
291 </DL>
292 <P>
293 <STRONG>Note that in all cases every <CODE>allow</CODE> and <CODE>deny</CODE>
294 statement is evaluated, there is no &quot;short-circuiting&quot;.</STRONG>
295 </P>
296 <P>
297 Example:
298 </P>
299 <BLOCKQUOTE><CODE>
300     order deny,allow<BR>
301     deny from all<BR>
302     allow from .ncsa.uiuc.edu<BR>
303 </CODE></BLOCKQUOTE>
304 <P>
305 Hosts in the ncsa.uiuc.edu domain are allowed access; all other hosts are
306 denied access.
307 </P>
308 <!--#include virtual="footer.html" -->
309 </BODY>
310 </HTML>