📄 core.html
字号:
# ......<br />
</span>
</Directory>
</code></p></div>
<p>正则表达式配置段将在所有普通的<code class="directive"><Directory></code>和<code>.htaccess</code>文件应用之后才予以考虑。所以正则表达式将匹配<code>/home/abc/public_html/abc</code>并予以应用。</p>
<p><strong>请注意:Apache对<code><Directory /></code>的默认访问权限为"<code>Allow from All</code>"。这意味着Apache将伺服任何通过URL映射的文件。我们建议您将这个配置做如下屏蔽:</strong></p>
<div class="example"><p><code>
<Directory /><br />
<span class="indent">
Order Deny,Allow<br />
Deny from All<br />
</span>
</Directory>
</code></p></div>
<p><strong>然后在您<em>想要</em>使之被访问的目录中覆盖此配置。参阅<a href="../misc/security_tips.html">安全提示</a>以获取更多详情。</strong></p>
<p>一般来说<code class="directive"><Directory></code>指令只会出现在<code>httpd.conf</code>文件中,但它们也可能出现在任何其它配置文件中。<code class="directive"><Directory></code>指令不可被嵌套使用,也不能出现在<code class="directive"><a href="#limit"><Limit></a></code>或<code class="directive"><a href="#limitexcept"><LimitExcept></a></code>配置段中。</p>
<h3>参见</h3>
<ul>
<li><a href="../sections.html"><Directory>、<Location>、<Files>配置段是如何工作的</a>中包含了当接受一个请求时,这些不同的配置段是如何组合工作的相关解释。</li>
</ul>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="DirectoryMatch" id="DirectoryMatch"><DirectoryMatch></a> <a name="directorymatch" id="directorymatch">指令</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><DirectoryMatch <var>regex</var>>
... </DirectoryMatch></code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>核心(C)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>core</td></tr>
</table>
<p><code class="directive"><DirectoryMatch></code>和<code></DirectoryMatch></code>用于封装一组指令。与<code class="directive"><a href="#directory"><Directory></a></code>类似,此指令将仅作用于指定名字的目录及其子目录。然而,它可以接受一个<a class="glossarylink" href="../glossary.html#regex" title="see glossary">正则表达式</a>作为参数。比如说:</p>
<div class="example"><p><code>
<DirectoryMatch "^/www/(.+/)*[0-9]{3}">
</code></p></div>
<p>将匹配<code>/www/</code>下所有由3个数字组成的目录。</p>
<h3>参见</h3>
<ul>
<li><code class="directive"><a href="#directory"><Directory></a></code>获取如何在普通的<code class="directive"><Directory></code>中使用正则表达式的描述。</li>
<li><a href="../sections.html"><Directory>、<Location>、<Files>配置段是如何工作的</a>中包含了当接受一个请求时,这些不同的配置段是如何组合工作的相关解释。</li>
</ul>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="DocumentRoot" id="DocumentRoot">DocumentRoot</a> <a name="documentroot" id="documentroot">指令</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>DocumentRoot <var>directory-path</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>DocumentRoot /usr/local/apache2/htdocs</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>核心(C)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>core</td></tr>
</table>
<p>此指令设置了<code class="program"><a href="../programs/httpd.html">httpd</a></code>伺服的目录。在没有使用类似<code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>这样的指令的情况下,服务器会将请求中的URL附加到<code>DocumentRoot</code>后面以构成指向文档的路径。比如说:</p>
<div class="example"><p><code>
DocumentRoot /usr/web
</code></p></div>
<p>于是对<code>http://www.my.host.com/index.html</code>的访问就会指向<code>/usr/web/index.html</code> 。如果<var>directory-path</var>不是绝对路径,则被假定为是相对于<code class="directive"><a href="#serverroot">ServerRoot</a></code>的路径。</p>
<p>指定<code class="directive">DocumentRoot</code>时不应包括最后的"/"。</p>
<h3>参见</h3>
<ul>
<li><a href="../urlmapping.html">从URL到文件系统的映射</a></li>
</ul>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="EnableMMAP" id="EnableMMAP">EnableMMAP</a> <a name="enablemmap" id="enablemmap">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>在递送中使用内存映射(memory-mapping)来读取文件</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>EnableMMAP On|Off</code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>EnableMMAP On</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">覆盖项</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>核心(C)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>core</td></tr>
</table>
<p>此指令指示<code class="program"><a href="../programs/httpd.html">httpd</a></code>在递送中如果需要读取一个文件的内容,它是否可以使用内存映射。当处理一个需要访问文件中的数据的请求时,比如说当递送一个使用<code class="module"><a href="../mod/mod_include.html">mod_include</a></code>进行服务器端分析的文件时,如果操作系统支持,Apache将默认使用内存映射。</p>
<p>这种内存映射有时会带来性能的提高,但在某些情况下,您可能会需要禁用内存映射以避免一些操作系统的问题:</p>
<ul>
<li>在一些多处理器的系统上,内存映射会减低一些<code class="program"><a href="../programs/httpd.html">httpd</a></code>的性能。</li>
<li>在挂载了NFS的<code class="directive"><a href="#documentroot">DocumentRoot</a></code>上,若已经将一个文件进行了内存映射,则删除或截断这个文件会造成<code class="program"><a href="../programs/httpd.html">httpd</a></code>因为分段故障而崩溃。</li>
</ul>
<p>在可能遇到这些问题的服务器配置过程中,您应当使用下面的命令来禁用内存映射:</p>
<div class="example"><p><code>
EnableMMAP Off
</code></p></div>
<p>对于挂载了NFS的文件夹,可以单独指定禁用内存映射:</p>
<div class="example"><p><code>
<Directory "/path-to-nfs-files">
<span class="indent">
EnableMMAP Off
</span>
</Directory>
</code></p></div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="EnableSendfile" id="EnableSendfile">EnableSendfile</a> <a name="enablesendfile" id="enablesendfile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>使用操作系统内核的sendfile支持来将文件发送到客户端</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>EnableSendfile On|Off</code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>EnableSendfile On</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">覆盖项</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>核心(C)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>core</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">兼容性</a></th><td>仅在 Apache 2.0.44 及以后的版本中可用</td></tr>
</table>
<p>这个指令控制<code class="program"><a href="../programs/httpd.html">httpd</a></code>是否可以使用操作系统内核的sendfile支持来将文件发送到客户端。默认情况下,当处理一个请求并不需要访问文件内部的数据时(比如发送一个静态的文件内容),如果操作系统支持,Apache将使用sendfile将文件内容直接发送到客户端而并不读取文件。</p>
<p>这个sendfile机制避免了分开的读和写操作以及缓冲区分配,但是在一些平台或者一些文件系统上,最好禁止这个特性来避免一些问题:</p>
<ul>
<li>一些平台可能会有编译系统检测不到的有缺陷的sendfile支持,特别是将在其他平台上使用交叉编译得到的二进制文件运行于当前对sendfile支持有缺陷的平台时。</li>
<li>在Linux上启用IPv6时,使用sendfile将会触发某些网卡上的TCP校验和卸载bug。</li>
<li>当Linux运行在Itanium处理器上的时候,sendfile可能无法处理大于2GB的文件。</li>
<li>对于一个通过网络挂载了NFS文件系统的<code class="directive"><a href="#documentroot">DocumentRoot</a></code> (比如:NFS或SMB),内核可能无法可靠的通过自己的缓冲区服务于网络文件。</li>
</ul>
<p>如果出现以上情况,你应当禁用sendfile :</p>
<div class="example"><p><code>
EnableSendfile Off
</code></p></div>
<p>针对NFS或SMB,这个指令可以被针对目录的设置覆盖:</p>
<div class="example"><p><code>
<Directory "/path-to-nfs-files">
<span class="indent">
EnableSendfile Off
</span>
</Directory>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -