📄 sections.html.en
字号:
Order allow,deny<br />Deny from all<br /></FilesMatch></code></p></div><h3><a name="whichwhen" id="whichwhen">What to use When</a></h3><p>Choosing between filesystem containers and webspace containers isactually quite easy. When applying directives to objects that residein the filesystem always use <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> or <code class="directive"><a href="./mod/core.html#files"><Files></a></code>. When applying directives to objectsthat do not reside in the filesystem (such as a webpage generated froma database), use <code class="directive"><a href="./mod/core.html#location"><Location></a></code>.</p><p>It is important to never use <code class="directive"><a href="./mod/core.html#location"><Location></a></code> when trying to restrictaccess to objects in the filesystem. This is because manydifferent webspace locations (URLs) could map to the same filesystemlocation, allowing your restrictions to be circumvented.For example, consider the following configuration:</p><div class="example"><p><code><Location /dir/><br />Order allow,deny<br />Deny from all<br /></Location></code></p></div><p>This works fine if the request is for<code>http://yoursite.example.com/dir/</code>. But what if you are ona case-insensitive filesystem? Then your restriction could be easilycircumvented by requesting<code>http://yoursite.example.com/DIR/</code>. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive, incontrast, will apply to any content served from that location,regardless of how it is called. (An exception is filesystem links.The same directory can be placed in more than one part of thefilesystem using symbolic links. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive will follow the symboliclink without resetting the pathname. Therefore, for the highest levelof security, symbolic links should be disabled with the appropriate<code class="directive"><a href="./mod/core.html#options">Options</a></code> directive.)</p><p>If you are, perhaps, thinking that none of this applies to youbecause you use a case-sensitive filesystem, remember that there aremany other ways to map multiple webspace locations to the samefilesystem location. Therefore you should always use the filesystemcontainers when you can. There is, however, one exception to thisrule. Putting configuration restrictions in a <code><Location/></code> section is perfectly safe because this section will applyto all requests regardless of the specific URL.</p></div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div><div class="section"><h2><a name="virtualhost" id="virtualhost">Virtual Hosts</a></h2><p>The <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code>container encloses directives that apply to specific hosts.This is useful when serving multiple hosts from the same machinewith a different configuration for each. For more information,see the <a href="vhosts/">Virtual Host Documentation</a>.</p></div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div><div class="section"><h2><a name="proxy" id="proxy">Proxy</a></h2><p>The <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code>containers apply enclosed configuration directives onlyto sites accessed through <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>'s proxy serverthat match the specified URL. For example, the following configurationwill prevent the proxy server from being used to access the<code>cnn.com</code> website.</p><div class="example"><p><code><Proxy http://cnn.com/*><br />Order allow,deny<br />Deny from all<br /></Proxy></code></p></div></div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div><div class="section"><h2><a name="whatwhere" id="whatwhere">What Directives are Allowed?</a></h2><p>To find out what directives are allowed in what types ofconfiguration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive.Everything that is allowed in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>sections is also syntactically allowed in<code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code>,<code class="directive"><a href="./mod/core.html#files"><Files></a></code>,<code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>,<code class="directive"><a href="./mod/core.html#location"><Location></a></code>,<code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code>,<code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>,and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code>sections. There are some exceptions, however:</p><ul><li>The <code class="directive"><a href="./mod/core.html#allowoverride">AllowOverride</a></code> directiveworks only in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>sections.</li><li>The <code>FollowSymLinks</code> and<code>SymLinksIfOwnerMatch</code> <code class="directive"><a href="./mod/core.html#options">Options</a></code> work only in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections or<code>.htaccess</code> files.</li><li>The <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive cannotbe used in <code class="directive"><a href="./mod/core.html#files"><Files></a></code>and <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>sections.</li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div><div class="section"><h2><a name="mergin" id="mergin">How the sections are merged</a></h2><p>The configuration sections are applied in a very particular order.Since this can have important effects on how configuration directivesare interpreted, it is important to understand how this works.</p> <p>The order of merging is:</p> <ol> <li> <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> (except regular expressions) and <code>.htaccess</code> done simultaneously (with <code>.htaccess</code>, if allowed, overriding <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>)</li> <li><code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code> (and <code><Directory ~></code>)</li> <li><code class="directive"><a href="./mod/core.html#files"><Files></a></code> and <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code> done simultaneously</li> <li><code class="directive"><a href="./mod/core.html#location"><Location></a></code> and <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code> done simultaneously</li> </ol> <p>Apart from <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>, each group is processed in the order that they appear in the configuration files. <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> (group 1 above) is processed in the order shortest directory component to longest. So for example, <code><Directory /var/web/dir></code> will be processed before <code><Directory /var/web/dir/subdir></code>. If multiple <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections apply to the same directory they are processed in the configuration file order. Configurations included via the <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive will be treated as if they were inside the including file at the location of the <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive.</p> <p>Sections inside <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code> sections are applied <em>after</em> the corresponding sections outside the virtual host definition. This allows virtual hosts to override the main server configuration.</p> <p>Later sections override earlier ones.</p><div class="note"><h3>Technical Note</h3> There is actually a <code><Location></code>/<code><LocationMatch></code> sequence performed just before the name translation phase (where <code>Aliases</code> and <code>DocumentRoots</code> are used to map URLs to filenames). The results of this sequence are completely thrown away after the translation has completed.</div><h3><a name="merge-examples" id="merge-examples">Some Examples</a></h3><p>Below is an artificial example to show the order ofmerging. Assuming they all apply to the request, the directives inthis example will be applied in the order A > B > C > D >E.</p><div class="example"><p><code><Location /><br />E<br /></Location><br /><br /><Files f.html><br />D<br /></Files><br /><br /><VirtualHost *><br /><Directory /a/b><br />B<br /></Directory><br /></VirtualHost><br /><br /><DirectoryMatch "^.*b$"><br />C<br /></DirectoryMatch><br /><br /><Directory /a/b><br />A<br /></Directory><br /><br /></code></p></div><p>For a more concrete example, consider the following. Regardless ofany access restrictions placed in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections, the <code class="directive"><a href="./mod/core.html#location"><Location></a></code> section will beevaluated last and will allow unrestricted access to the server. Inother words, order of merging is important, so be careful!</p><div class="example"><p><code><Location /><br />Order deny,allow<br />Allow from all<br /></Location><br /><br /># Woops! This <Directory> section will have no effect<br /><Directory /><br />Order allow,deny<br />Allow from all<br />Deny from badguy.example.com<br /></Directory></code></p></div></div></div><div class="bottomlang"><p><span>Available Languages: </span><a href="./en/sections.html" title="English"> en </a> |<a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |<a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p></div><div id="footer"><p class="apache">Copyright 1995-2005 The Apache Software Foundation or its licensors, as applicable.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p><p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -