<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; Apache基础知识</title>
	<atom:link href="http://ourapache.com/archives/category/basic/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>HTTP 状态代码解释</title>
		<link>http://ourapache.com/archives/324</link>
		<comments>http://ourapache.com/archives/324#comments</comments>
		<pubDate>Tue, 13 Apr 2010 05:17:23 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[HTTP相关知识]]></category>
		<category><![CDATA[状态]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=324</guid>
		<description><![CDATA[    如果向您的服务器发出了某项请求要求显示您网站上的某个网页（例如，当用户通过浏览器访问您的网页或在 Googlebot 抓取该网页时），那么，您的服务器会返回 HTTP 状态代码以响应该请求。

    此状态代码提供了有关请求状态的信息，且为 Googlebot 提供了有关您网站和请求的网页的信息。]]></description>
			<content:encoded><![CDATA[<h2>HTTP 状态代码</h2>
<p>如果向您的服务器发出了某项请求要求显示您网站上的某个网页（例如，当用户通过浏览器访问您的网页或在 Googlebot 抓取该网页时），那么，您的服务器会返回 HTTP 状态代码以响应该请求。</p>
<p>此状态代码提供了有关请求状态的信息，且为 Googlebot 提供了有关您网站和请求的网页的信息。</p>
<p>一些常见的状态代码为：</p>
<p><strong>200</strong> &#8211; 服务器成功返回网页<strong>404</strong> &#8211; 请求的网页不存在<strong>503</strong> &#8211; 服务器暂时不可用以下提供了 HTTP 状态代码的完整列表。点击链接可了解详细信息。您也可以访问<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">有关 HTTP 状态代码的 W3C 页来了解详细信息</a>。</p>
<p><strong>1xx</strong><strong>（临时响应）</strong></p>
<p>用于表示临时响应并需要请求者执行操作才能继续的状态代码。</p>
<table border="1" cellspacing="1" cellpadding="1" summary="1xx status codes indicating a provisional response">
<tbody>
<tr>
<th scope="col">代码</th>
<th scope="col">说明</th>
</tr>
<tr>
<td>100（继续）</td>
<td>请求者应当继续提出请求。服务器返回此代码则意味着，服务器已收到了请求的第一部分，现正在等待接收其余部分。</td>
</tr>
<tr>
<td>101（切换协议）</td>
<td>请求者已要求服务器切换协议，服务器已确认并准备进行切换。</td>
</tr>
</tbody>
</table>
<p><strong>2xx</strong><strong>（成功）</strong></p>
<p>用于表示服务器已成功处理了请求的状态代码。</p>
<table border="1" cellspacing="1" cellpadding="1" summary="2xx status codes indicating successful requests">
<tbody>
<tr>
<th scope="col">代码</th>
<th scope="col">说明</th>
</tr>
<tr>
<td>200（成功）</td>
<td>服务器已成功处理了请求。通常，这表示服务器提供了请求的网页。如果您的 robots.txt 文件显示为此状态，那么，这表示 Googlebot 已成功检索到该文件。</td>
</tr>
<tr>
<td>201（已创建）</td>
<td>请求成功且服务器已创建了新的资源。</td>
</tr>
<tr>
<td>202（已接受）</td>
<td>服务器已接受了请求，但尚未对其进行处理。</td>
</tr>
<tr>
<td>203（非授权信息）</td>
<td>服务器已成功处理了请求，但返回了可能来自另一来源的信息。</td>
</tr>
<tr>
<td>204（无内容）</td>
<td>服务器成功处理了请求，但未返回任何内容。</td>
</tr>
<tr>
<td>205（重置内容）</td>
<td>服务器成功处理了请求，但未返回任何内容。与 204 响应不同，此响应要求请求者重置文档视图（例如清除表单内容以输入新内容）。</td>
</tr>
<tr>
<td>206（部分内容）</td>
<td>服务器成功处理了部分 GET 请求。</td>
</tr>
</tbody>
</table>
<p><strong>3xx</strong><strong>（已重定向）</strong></p>
<p>要完成请求，您需要进一步进行操作。通常，这些状态代码是永远重定向的。Google 建议您在每次请求时使用的重定向要少于 5 个。您可以使用网站管理员工具来查看 Googlebot 在抓取您已重定向的网页时是否会遇到问题。<strong>诊断</strong>下的<a href="http://www.google.com/support/webmasters/bin/answer.py?answer=35156">抓取错误</a>页中列出了 Googlebot 由于重定向错误而无法抓取的网址。</p>
<table border="1" cellspacing="1" cellpadding="1" summary="3xx status codes requiring further action">
<tbody>
<tr>
<th scope="col">代码</th>
<th scope="col">说明</th>
</tr>
<tr>
<td>300（多种选择）</td>
<td>服务器根据请求可执行多种操作。服务器可根据请求者 (User agent) 来选择一项操作，或提供操作列表供请求者选择。</td>
</tr>
<tr>
<td><a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a>（永久移动）</td>
<td>请求的网页已被永久移动到新位置。服务器返回此响应（作为对 GET 或 HEAD 请求的响应）时，会自动将请求者转到新位置。您应使用此代码通知 Googlebot 某个网页或网站已被永久移动到新位置。</td>
</tr>
<tr>
<td>302（临时移动）</td>
<td>服务器目前正从不同位置的网页响应请求，但请求者应继续使用原有位置来进行以后的请求。此代码与响应 GET 和 HEAD 请求的 301 代码类似，会自动将请求者转到不同的位置。但由于 Googlebot 会继续抓取原有位置并将其编入索引，因此您不应使用此代码来通知 Googlebot 某个页面或网站已被移动。</td>
</tr>
<tr>
<td>303（查看其他位置）</td>
<td>当请求者应对不同的位置进行单独的 GET 请求以检索响应时，服务器会返回此代码。对于除 HEAD 请求之外的所有请求，服务器会自动转到其他位置。</td>
</tr>
<tr>
<td>304（未修改）</td>
<td>自从上次请求后，请求的网页未被修改过。服务器返回此响应时，不会返回网页内容。</p>
<p>如果网页自请求者上次请求后再也没有更改过，您应当将服务器配置为返回此响应（称为 If-Modified-Since HTTP 标头）。由于服务器可以告诉 Googlebot 自从上次抓取后网页没有更改过，因此可节省带宽和开销</p>
<p>。</td>
</tr>
<tr>
<td>305（使用代理）</td>
<td>请求者只能使用代理访问请求的网页。如果服务器返回此响应，那么，服务器还会指明请求者应当使用的代理。</td>
</tr>
<tr>
<td>307（临时重定向）</td>
<td>服务器目前正从不同位置的网页响应请求，但请求者应继续使用原有位置来进行以后的请求。此代码与响应 GET 和 HEAD 请求的 301 代码类似，会自动将请求者转到不同的位置。但由于 Googlebot 会继续抓取原有位置并将其编入索引，因此您不应使用此代码来通知 Googlebot 某个页面或网站已被移动。</td>
</tr>
</tbody>
</table>
<p><strong>4xx（请求错误）</strong></p>
<p>这些状态代码表示，请求可能出错，已妨碍了服务器对请求的处理。</p>
<table border="1" cellspacing="1" cellpadding="1" summary="4xx status codes indicating that the server could not process the request">
<tbody>
<tr>
<th scope="col">代码</th>
<th scope="col">说明</th>
</tr>
<tr>
<td>400（错误请求）</td>
<td>服务器不理解请求的语法。</td>
</tr>
<tr>
<td>401（未授权）</td>
<td>请求要求进行身份验证。登录后，服务器可能会返回对页面的此响应。</td>
</tr>
<tr>
<td>403（已禁止）</td>
<td>服务器拒绝请求。如果在 Googlebot 尝试抓取您网站上的有效网页时显示此状态代码（您可在 Google 网站管理员工具中<strong>诊断</strong>下的<strong>网络抓取</strong>页面上看到此状态代码），那么，这可能是您的服务器或主机拒绝 Googlebot 对其进行访问。</td>
</tr>
<tr>
<td>404（未找到）</td>
<td>服务器找不到请求的网页。例如，如果请求是针对服务器上不存在的网页进行的，那么，服务器通常会返回此代码。</p>
<p>如果您的网站上没有 robots.txt 文件，而您在 Google 网站管理员工具<a href="http://www.google.com/support/webmasters/bin/answer.py?answer=35237">“诊断”标签的 robots.txt 页</a>上发现此状态，那么，这是正确的状态。然而，如果您有 robots.txt 文件而又发现了此状态，那么，这说明您的 robots.txt 文件可能是命名错误或位于错误的位置。（该文件应当位于顶级域名上，且应当名为 robots.txt）。</p>
<p>如果您在 Googlebot 尝试抓取的网址上发现此状态（位于”诊断”标签的 HTTP 错误页上），那么，这表示 Googlebot 所追踪的可能是另一网页中的无效链接（旧链接或输入有误的链接）。</td>
</tr>
<tr>
<td>405（方法禁用）</td>
<td>禁用请求中所指定的方法。</td>
</tr>
<tr>
<td>406（不接受）</td>
<td>无法使用请求的内容特性来响应请求的网页。</td>
</tr>
<tr>
<td>407（需要代理授权）</td>
<td>此状态代码与 401（未授权）类似，但却指定了请求者应当使用代理进行授权。如果服务器返回此响应，那么，服务器还会指明请求者应当使用的代理。</td>
</tr>
<tr>
<td>408（请求超时）</td>
<td>服务器等候请求时超时。</td>
</tr>
<tr>
<td>409（冲突）</td>
<td>服务器在完成请求时发生冲突。服务器必须包含有关响应中所发生的冲突的信息。服务器在响应与前一个请求相冲突的 PUT 请求时可能会返回此代码，同时会提供两个请求的差异列表。</td>
</tr>
<tr>
<td>410（已删除）</td>
<td>如果请求的资源已被永久删除，那么，服务器会返回此响应。该代码与 404（未找到）代码类似，但在资源以前有但现在已经不复存在的情况下，有时会替代 404 代码出现。如果资源已被永久删除，那么，您应当使用 301 代码指定该资源的新位置。</td>
</tr>
<tr>
<td>411（需要有效长度）</td>
<td>服务器不会接受包含无效内容长度标头字段的请求。</td>
</tr>
<tr>
<td>412（未满足前提条件）</td>
<td>服务器未满足请求者在请求中设置的其中一个前提条件。</td>
</tr>
<tr>
<td>413（请求实体过大）</td>
<td>服务器无法处理请求，因为请求实体过大，已超出服务器的处理能力。</td>
</tr>
<tr>
<td>414（请求的 URI 过长）</td>
<td>请求的 URI（通常为网址）过长，服务器无法进行处理。</td>
</tr>
<tr>
<td>415（不支持的媒体类型）</td>
<td>请求的格式不受请求页面的支持。</td>
</tr>
<tr>
<td>416（请求范围不符合要求）</td>
<td>如果请求是针对网页的无效范围进行的，那么，服务器会返回此状态代码。</td>
</tr>
<tr>
<td>417（未满足期望值）</td>
<td>服务器未满足”期望”请求标头字段的要求。</td>
</tr>
</tbody>
</table>
<p><strong>5xx</strong><strong>（服务器错误）</strong></p>
<p>这些状态代码表示，服务器在尝试处理请求时发生内部错误。这些错误可能是服务器本身的错误，而不是请求出错。</p>
<table border="1" cellspacing="1" cellpadding="1" summary="5xx status codes indicating that the server had an internal error">
<tbody>
<tr>
<th scope="col">代码</th>
<th scope="col">说明</th>
</tr>
<tr>
<td>500（服务器内部错误）</td>
<td>服务器遇到错误，无法完成请求。</td>
</tr>
<tr>
<td>501（尚未实施）</td>
<td>服务器不具备完成请求的功能。例如，当服务器无法识别请求方法时，服务器可能会返回此代码。</td>
</tr>
<tr>
<td>502（错误网关）</td>
<td>服务器作为网关或代理，从上游服务器收到了无效的响应。</td>
</tr>
<tr>
<td>503（服务不可用）</td>
<td>目前无法使用服务器（由于超载或进行停机维护）。通常，这只是一种暂时的状态。</td>
</tr>
<tr>
<td>504（网关超时）</td>
<td>服务器作为网关或代理，未及时从上游服务器接收请求。</td>
</tr>
<tr>
<td>505（HTTP 版本不受支持）</td>
<td>服务器不支持请求中所使用的 HTTP 协议版本。</td>
</tr>
</tbody>
</table>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月10号 -- <a href="http://ourapache.com/archives/111" title="Apache 中内存管理的三种境界 ">Apache 中内存管理的三种境界 </a></li><li>2009年09月6号 -- <a href="http://ourapache.com/archives/303" title="基于资源的HTTP Cache的实现介绍">基于资源的HTTP Cache的实现介绍</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/211" title="Apache common-pool, common-dbcp源码解读与对象池原理剖析">Apache common-pool, common-dbcp源码解读与对象池原理剖析</a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/21" title="关于keepalive的解释">关于keepalive的解释</a></li><li>2009年07月14号 -- <a href="http://ourapache.com/archives/263" title="初识HTTP中的Referer">初识HTTP中的Referer</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/85" title="apache之404错误页面">apache之404错误页面</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/87" title="Linux下查看apache连接数">Linux下查看apache连接数</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/273" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/http" title="HTTP相关知识" rel="tag">HTTP相关知识</a>, <a href="http://ourapache.com/archives/tag/%e7%8a%b6%e6%80%81" title="状态" rel="tag">状态</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/324/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache 的AcceptMutex 的理解</title>
		<link>http://ourapache.com/archives/322</link>
		<comments>http://ourapache.com/archives/322#comments</comments>
		<pubDate>Tue, 13 Apr 2010 05:15:48 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[AcceptMutex]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=322</guid>
		<description><![CDATA[当apache监听多个端口或多个ip上的端口时，多个子进程是怎么分工的呢？和只监听一个端口有什么区别吗？]]></description>
			<content:encoded><![CDATA[<p>当apache监听多个端口或多个ip上的端口时，多个子进程是怎么分工的呢？和只监听一个端口有什么区别吗？</p>
<p>1. 如果apache的多个进程只监听一个端口，则不需要AcceptMutex，每个apache进程都在执行accept操作，发现请求后就开始执行，执行完继续accept，多个进程之间不会相互干扰，这是由accept的机制来完成的。</p>
<p>2. 如果apache的多个进程只监听socket多于一个，则不能直接accept了，就必须使用select或poll机制来发现知否有请求需要执行，发现之后，再由accept来接受请求；然而select或poll没有accept那么能自动处理互斥的问题，这时候就需要一个“锁”了，就是所谓的AcceptMutex，AcceptMutex的实现形式有多种，这个不属于本文讨论的范围。</p>
<p>下面是apache在监听三个socket（[16 17 18]）时，其中一个进程的表现：</p>
<p>semop(524288, 0x81dd334, 1)             = 0</p>
<p>select(19, [16 17 18], NULL, NULL, NULL) = 1 (in [17])</p>
<p>accept(17, {sa_family=AF_INET, sin_port=htons(52932), sin_addr=inet_addr(“10.55.38.9&#8243;)}, [16]) = 29</p>
<p>semop(524288, 0x81dd33a, 1)             = 0</p>
<p>第一步：先获取锁（0x81dd334）， 同一时刻只有一个进程能获取锁</p>
<p>第二步：开始select（对于apache2这里好像是poll，poll的效率更高一些），并且发现17需要处理了</p>
<p>第三步：accept 17</p>
<p>第四步：释放锁，这样其它进程就可以获取锁并处理后续的请求了</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li><li>2009年07月14号 -- <a href="http://ourapache.com/archives/263" title="初识HTTP中的Referer">初识HTTP中的Referer</a></li><li>2009年06月14号 -- <a href="http://ourapache.com/archives/255" title="常见的rewrite规则大全">常见的rewrite规则大全</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/312" title="apache配置（如何禁止列出目录内容）">apache配置（如何禁止列出目录内容）</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/275" title="Apache+Django性能优化之mod_wsgi篇">Apache+Django性能优化之mod_wsgi篇</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/35" title="不再为Apache进程淤积、耗尽内存而困扰">不再为Apache进程淤积、耗尽内存而困扰</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/187" title="header中的Cache-control参数说明">header中的Cache-control参数说明</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/200" title="header常用指令">header常用指令</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/acceptmutex" title="AcceptMutex" rel="tag">AcceptMutex</a>, <a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/322/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache配置（如何禁止列出目录内容）</title>
		<link>http://ourapache.com/archives/312</link>
		<comments>http://ourapache.com/archives/312#comments</comments>
		<pubDate>Sat, 12 Dec 2009 15:37:21 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[目录]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=312</guid>
		<description><![CDATA[只需要将访问目录的Options 内部的Indexes去掉即可。]]></description>
			<content:encoded><![CDATA[<p>只需要将访问目录的Options 内部的Indexes去掉即可。</p>
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#fdfddf"><span style="font-weight: bold;">以下是代码片段：</span><br />
        &lt;Directory /home/blog/piwigo-2.0.5&gt;<br />
                #Options Indexes FollowSymLinks MultiViews<br />
                Options FollowSymLinks MultiViews<br />
                AllowOverride all<br />
                Order allow,deny<br />
                allow from all<br />
        &lt;/Directory&gt;</td>
</tr>
</tbody>
</table>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月27号 -- <a href="http://ourapache.com/archives/211" title="Apache common-pool, common-dbcp源码解读与对象池原理剖析">Apache common-pool, common-dbcp源码解读与对象池原理剖析</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/68" title="apache最大连接数性能测试">apache最大连接数性能测试</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/119" title="Apache2运用mod_deflate提升网络页面浏览速度">Apache2运用mod_deflate提升网络页面浏览速度</a></li><li>2009年02月12号 -- <a href="http://ourapache.com/archives/132" title="apache core段的DocumentRoot与访问权限 ">apache core段的DocumentRoot与访问权限 </a></li><li>2009年09月2号 -- <a href="http://ourapache.com/archives/299" title="针对$_SERVER['PHP_SELF']的跨站脚本攻击（XSS）">针对$_SERVER['PHP_SELF']的跨站脚本攻击（XSS）</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/273" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/%e7%9b%ae%e5%bd%95" title="目录" rel="tag">目录</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/312/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.htaccess的301跳转</title>
		<link>http://ourapache.com/archives/310</link>
		<comments>http://ourapache.com/archives/310#comments</comments>
		<pubDate>Sat, 12 Dec 2009 15:35:29 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[跳转]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=310</guid>
		<description><![CDATA[.htaccess的301跳转]]></description>
			<content:encoded><![CDATA[<p>server:linux(ubuntu)</p>
<p>add <a href="http://ourapache.com/archives/tag/mod_rewrite" class="st_tag internal_tag" rel="tag" title="标签 mod_rewrite 下的日志">mod_rewrite</a>:1、sudo a2enmod <a href="http://ourapache.com/archives/tag/rewrite" class="st_tag internal_tag" rel="tag" title="标签 rewrite 下的日志">rewrite</a> 2、udo vim /etc/apache2/sites-enabled/000-default</p>
<p>将其中的：</p>
<p>AllowOverride None</p>
<p>修改为：</p>
<p>AllowOverride All</p>
<p>重启生效。</p>
<p>将 htmldata.cn 转换为 www.htmldata.cn</p>
<div class="codecolorer-container text " style="overflow: auto; white-space: nowrap;">
<div class="text codecolorer" style="white-space: nowrap;">
<table style="table-layout: fixed; border: #cccccc 1px dotted;" border="0" cellspacing="0" cellpadding="6" width="95%" align="center">
<tbody>
<tr>
<td style="word-wrap: break-word;" bgcolor="#f3f3f3"><span style="font-weight: bold;">以下是引用片段：</span><br />
Options +FollowSymlinks<br />
RewriteEngine on<br />
rewritecond %{http_host} ^htmldata.cn [nc]<br />
rewriterule ^(.*)$ http://www.htmldata.cn/$1 [r=<a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a>,nc]</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/97" title="使用apache下的301设置来做域名的更换转移">使用apache下的301设置来做域名的更换转移</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/301" title="301" rel="tag">301</a>, <a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://ourapache.com/archives/tag/%e8%b7%b3%e8%bd%ac" title="跳转" rel="tag">跳转</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/310/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache两种运行方式比较:Standalone和inetd</title>
		<link>http://ourapache.com/archives/292</link>
		<comments>http://ourapache.com/archives/292#comments</comments>
		<pubDate>Sun, 16 Aug 2009 14:33:57 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[inetd]]></category>
		<category><![CDATA[Standalone]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=292</guid>
		<description><![CDATA[standalone模式表示Apache进程以一个单独的守护进程方式在后台监听是否有客户端的请求，如果有则生成一个子进程来为其服务。在 standalone模式下，apache进程一次性启动，运行期间一直驻留在内存中，尽管损耗了一定的系统资源，但接入信号反应快；而且子httpd进 程在http请求完毕后并没有直接断掉，这样就可以重新用来接受新的http请求，请参考apache的keepalive指令（请看这里）。由于不存在对每个请求都启动新的apache根进程，所以它的效率更高。
inetd模式表示Apache服务不是以一个单独的守候进程的形式支持。而是由Inetd这个超级守候进程进行代劳，当它监听一个客户端的http请求 的时候，再启动一个httpd进程为其服务。一个由inted运行的服务器进程在它结束对请求服务的同时立刻退出，虽然不占用了系统资源，但是也由此不适 合应用在同时连接数量较多的系统。因为如果请求完毕后就结束httpd进程，会使服务器负担加重。]]></description>
			<content:encoded><![CDATA[<p>那天和大家分享了<a href="http://www.ourapache.com/archives/288" target="_blank">Apache常见两种工作模式</a>的对比。今天和大家分享下Apache的两种运行方式(Standalone和inetd)的比较。</p>
<p><strong>standalone模式</strong>表示Apache进程以一个单独的守护进程方式在后台监听是否有客户端的请求，如果有则生成一个子进程来为其服务。在 standalone模式下，apache进程一次性启动，运行期间一直驻留在内存中，尽管损耗了一定的系统资源，但接入信号反应快；而且子httpd进 程在http请求完毕后并没有直接断掉，这样就可以重新用来接受新的http请求，请参考apache的keepalive指令（<a href="http://www.ourapache.com/archives/tag/keepalive" target="_blank">请看这里</a>）。由于不存在对每个请求都启动新的apache根进程，所以它的效率更高。</p>
<p><strong>inetd模式</strong>表示Apache服务不是以一个单独的守候进程的形式支持。而是由Inetd这个超级守候进程进行代劳，当它监听一个客户端的http请求 的时候，再启动一个httpd进程为其服务。一个由inted运行的服务器进程在它结束对请求服务的同时立刻退出，虽然不占用了系统资源，但是也由此不适 合应用在同时连接数量较多的系统。因为如果请求完毕后就结束httpd进程，会使服务器负担加重。</p>
<p>具体使用如下：</p>
<p><strong>standalone模式</strong></p>
<p>此种模式下，Apache服务器监听特定端口的连接请求。当用户发起特定端口地址的连接请求时，主服务器进程启动子httpd进程来响应该请求。</p>
<p>这样还需要告诉主服务器进程侦听的特定端口地址，使用命令：</p>
<blockquote><p>Port [number] （缺省值为80）</p></blockquote>
<p><strong>inetd模式</strong></p>
<p>inetd是监听所有小于1024的端口连接请求的Internet守护进程(一个服务器进程)。与standalone模式不同，当客户系统发出到Apache服务器的连接请求时，inetd启动一个httpd进程，由此进程服务此请求，完成服务后即退出。</p>
<p>如果选择通过inetd服务器来运行Apache，需要编辑/etc/<a href="http://ourapache.com/archives/tag/inetd" class="st_tag internal_tag" rel="tag" title="标签 inetd 下的日志">inetd</a>.conf文件为Apache添加一条新的记录：</p>
<blockquote><p>httpd stream <a href="http://ourapache.com/archives/tag/tcp" class="st_tag internal_tag" rel="tag" title="标签 tcp 下的日志">tcp</a> nowait httpd /etc/httpd/bin/httpd –f /etc/httpd/conf/httpd.conf</p></blockquote>
<p>修改了/etc/inetd.conf文件后，就需要修改/etc/services中添加一行</p>
<blockquote><p>httpd 80/tcp httpd</p></blockquote>
<p>做完以上修改后，需要重新启动inetd进程。首先，使用以下命令取得inetd的进程ID：</p>
<blockquote><p>ps auxw | grep inetd</p></blockquote>
<p>然后执行命令：kill -HUP pid</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月25号 -- <a href="http://ourapache.com/archives/168" title="apache ab压力测试收藏">apache ab压力测试收藏</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/270" title="Apache配置之URL重写">Apache配置之URL重写</a></li><li>2009年08月12号 -- <a href="http://ourapache.com/archives/265" title="关于apache的restart和stop, start的问题">关于apache的restart和stop, start的问题</a></li><li>2009年09月2号 -- <a href="http://ourapache.com/archives/299" title="针对$_SERVER['PHP_SELF']的跨站脚本攻击（XSS）">针对$_SERVER['PHP_SELF']的跨站脚本攻击（XSS）</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2008年12月29号 -- <a href="http://ourapache.com/archives/17" title="使用apachebench进行post压力测试">使用apachebench进行post压力测试</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/79" title="TCP 相关参数解释">TCP 相关参数解释</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/181" title="Apache并发控制、查看进程数、TCP连接、压缩功能说明">Apache并发控制、查看进程数、TCP连接、压缩功能说明</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/284" title="Apache负载均衡设置方法: mod_proxy">Apache负载均衡设置方法: mod_proxy</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/inetd" title="inetd" rel="tag">inetd</a>, <a href="http://ourapache.com/archives/tag/standalone" title="Standalone" rel="tag">Standalone</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/292/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache两种常用工作模式比较:prefork和worker</title>
		<link>http://ourapache.com/archives/288</link>
		<comments>http://ourapache.com/archives/288#comments</comments>
		<pubDate>Sun, 16 Aug 2009 14:21:06 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[worker]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=288</guid>
		<description><![CDATA[在这里我就prefork和worker两种最为常用的工作模式进行比较：

prefork–Unix平台上的默认（缺省）MPM，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接，效率高，但内存占用量比较大。

worker–使用多个子进程，每个子进程有多个线程，每个线程在某个确定的时间只能维持一个连接，内存占用量比较小，适合高流量的http服务器。缺点是假如一个线程崩溃，整个进程就会连同其任何线程一起”死掉”，所以要保证一个程式在运行时必须被系统识别为”每 个线程都是安全的”。]]></description>
			<content:encoded><![CDATA[<p>以前一直在用Apache，却也一直不知道它有那么多的工作模式，看了手册才知道，囧！</p>
<p>在这里我就prefork和worker两种最为常用的工作模式进行比较：</p>
<p><a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a>–Unix平台上的默认（缺省）MPM，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接，效率高，但内存占用量比较大。</p>
<p><a href="http://ourapache.com/archives/tag/worker" class="st_tag internal_tag" rel="tag" title="标签 worker 下的日志">worker</a>–使用多个子进程，每个子进程有多个线程，每个线程在某个确定的时间只能维持一个连接，内存占用量比较小，适合高流量的http服务器。缺点是假如一个线程崩溃，整个进程就会连同其任何线程一起”死掉”，所以要保证一个程式在运行时必须被系统识别为”每 个线程都是安全的”。</p>
<p>了解了这些个之后，怎么才能知道你的Apache服务器工作在什么状态呢？使用“apachectl -l”命令就可以显示出来。</p>
<p>Apache的默认的工作模式为prefork，如何把它改成worker模式呢？</p>
<p>如果你还未编译安装，那就简单了，在编译的时候加个参数 “–with-mpm=worker”，就好了；</p>
<p>如果你想更改正在运行的Apache的工作模式：</p>
<p>1.将当前的prefork模式启动文件改名</p>
<blockquote><p>mv httpd httpd.prefork</p></blockquote>
<p>2.将worker模式的启动文件改名</p>
<blockquote><p>mv httpd.worker httpd</p></blockquote>
<p>3.修改Apache配置文件</p>
<blockquote><p>vi /usr/local/apache2/conf/extra/httpd-mpm.conf</p></blockquote>
<p>找到里边的如下一段，可适当修改负载等参数：</p>
<blockquote><p>StartServers 2<br />
MaxClients 150<br />
MinSpareThreads 25<br />
MaxSpareThreads 75<br />
ThreadsPerChild 25<br />
MaxRequestsPerChild 0</p></blockquote>
<p>4.重新启动服务</p>
<blockquote><p>/usr/local/apache2/bin/apachectl <a href="http://ourapache.com/archives/tag/restart" class="st_tag internal_tag" rel="tag" title="标签 restart 下的日志">restart</a></p></blockquote>
<p>PS：处于稳定性和安全性考虑，在真正的生产环境，请勿轻易改变其工作模式。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/232" title="Apache Prefork和Worker模式的性能比较测试">Apache Prefork和Worker模式的性能比较测试</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/222" title="Apache 2.0中prefork.c模块和worker.c模块的比较">Apache 2.0中prefork.c模块和worker.c模块的比较</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/229" title="对Apache中并发控制参数prefork理解和调优">对Apache中并发控制参数prefork理解和调优</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/62" title="对apache中并发控制参数prefork理解和调优">对apache中并发控制参数prefork理解和调优</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a>, <a href="http://ourapache.com/archives/tag/worker" title="worker" rel="tag">worker</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/288/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux下查看nginx，apache，mysql，php的编译参数</title>
		<link>http://ourapache.com/archives/286</link>
		<comments>http://ourapache.com/archives/286#comments</comments>
		<pubDate>Thu, 13 Aug 2009 15:57:00 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[编译]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=286</guid>
		<description><![CDATA[有时候nginx，apache，mysql，php编译完了想看看编译参数可以用以下方法]]></description>
			<content:encoded><![CDATA[<p>有时候nginx，apache，<a href="http://ourapache.com/archives/tag/mysql" class="st_tag internal_tag" rel="tag" title="标签 mysql 下的日志">mysql</a>，php编译完了想看看编译参数可以用以下方法</p>
<p><strong>nginx编译参数：</strong></p>
<blockquote><p>#/usr/local/<a href="http://ourapache.com/archives/tag/nginx" class="st_tag internal_tag" rel="tag" title="标签 nginx 下的日志">nginx</a>/sbin/<a href="http://ourapache.com/archives/tag/nginx" class="st_tag internal_tag" rel="tag" title="标签 nginx 下的日志">nginx</a> -V<br />
nginx version: nginx/0.6.32</p>
<p>built by gcc 4.1.2 20071124 (Red Hat 4.1.2-42)</p>
<p>configure arguments: &#8211;user=www &#8211;group=www &#8211;prefix=/usr/local/nginx/ &#8211;with-http_stub_status_module &#8211;with-openssl=/usr/local/openssl</p></blockquote>
<p><strong>apache编译参数：</strong></p>
<blockquote><p># cat /usr/local/apache2/build/config.nice<br />
#! /bin/sh</p>
<p>#</p>
<p># Created by configure</p>
<p>“./configure” \</p>
<p>“&#8211;prefix=/usr/local/apache2&#8243; \</p>
<p>“&#8211;with-included-apr” \</p>
<p>“&#8211;enable-so” \</p>
<p>“&#8211;enable-deflate=shared” \</p>
<p>“&#8211;enable-expires=shared” \</p>
<p>“&#8211;enable-<a href="http://ourapache.com/archives/tag/rewrite" class="st_tag internal_tag" rel="tag" title="标签 rewrite 下的日志">rewrite</a>=shared” \</p>
<p>“&#8211;enable-static-support” \</p>
<p>“&#8211;disable-userdir” \</p>
<p>“$@”</p></blockquote>
<p><strong>php编译参数：</strong></p>
<blockquote><p># /usr/local/<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a>/bin/<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> -i |grep configure</p>
<p>Configure Command =&gt; &#8216;./configure&#8217; &#8216;&#8211;prefix=/usr/local/php&#8217; &#8216;&#8211;with-<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a>2=/usr/local/apache2/bin/<a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a>&#8217; &#8216;&#8211;with-config-file-path=/usr/local/php/etc&#8217; &#8216;&#8211;with-mysql=/usr/local/mysql&#8217; &#8216;&#8211;with-libxml-dir=/usr/local/libxml2/bin&#8217; &#8216;&#8211;with-gd=/usr/local/gd2&#8242; &#8216;&#8211;with-jpeg-dir&#8217; &#8216;&#8211;with-png-dir&#8217; &#8216;&#8211;with-bz2&#8242; &#8216;&#8211;with-xmlrpc&#8217; &#8216;&#8211;with-freetype-dir&#8217; &#8216;&#8211;with-zlib-dir&#8217;</p></blockquote>
<p><strong>mysql编译参数：</strong></p>
<blockquote><p># cat “/usr/local/mysql/bin/mysqlbug”|grep configure</p>
<p># This is set by configure</p>
<p>CONFIGURE_LINE=”./configure &#8216;&#8211;prefix=/usr/local/mysql&#8217; &#8216;&#8211;localstatedir=/var/lib/mysql&#8217; &#8216;&#8211;with-comment=Source&#8217; &#8216;&#8211;with-server-suffix=-H863&#8242; &#8216;&#8211;with-mysqld-user=mysql&#8217; &#8216;&#8211;without-debug&#8217; &#8216;&#8211;with-big-tables&#8217; &#8216;&#8211;with-charset=gbk&#8217; &#8216;&#8211;with-collation=gbk_chinese_ci&#8217; &#8216;&#8211;with-extra-charsets=all&#8217; &#8216;&#8211;with-pthread&#8217; &#8216;&#8211;enable-static&#8217; &#8216;&#8211;enable-thread-safe-client&#8217; &#8216;&#8211;with-client-ldflags=-all-static&#8217; &#8216;&#8211;with-mysqld-ldflags=-all-static&#8217; &#8216;&#8211;enable-assembler&#8217; &#8216;&#8211;without-isam&#8217; &#8216;&#8211;without-innodb&#8217; &#8216;&#8211;without-ndb-debug&#8217;”</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年01月6号 -- <a href="http://ourapache.com/archives/27" title="php+mysql+apache编码深度解析">php+mysql+apache编码深度解析</a></li><li>2009年06月7号 -- <a href="http://ourapache.com/archives/251" title="apxs是Apache编译和安装扩展模块的工具">apxs是Apache编译和安装扩展模块的工具</a></li><li>2009年02月17号 -- <a href="http://ourapache.com/archives/142" title="在64位机器上关于Apache 2.2.3版的编译问题">在64位机器上关于Apache 2.2.3版的编译问题</a></li><li>2009年01月5号 -- <a href="http://ourapache.com/archives/19" title="重大漏洞, 让Apache上传不安全-php.rar">重大漏洞, 让Apache上传不安全-php.rar</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/mysql" title="mysql" rel="tag">mysql</a>, <a href="http://ourapache.com/archives/tag/nginx" title="nginx" rel="tag">nginx</a>, <a href="http://ourapache.com/archives/tag/php" title="php" rel="tag">php</a>, <a href="http://ourapache.com/archives/tag/%e7%bc%96%e8%af%91" title="编译" rel="tag">编译</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/286/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>关于apache的restart和stop, start的问题</title>
		<link>http://ourapache.com/archives/265</link>
		<comments>http://ourapache.com/archives/265#comments</comments>
		<pubDate>Wed, 12 Aug 2009 15:52:27 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[graceful]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[stop]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=265</guid>
		<description><![CDATA[昨天解决问题的时候，用restart没有生效，没有仔细研究，今天查了下资料，有点了解了。]]></description>
			<content:encoded><![CDATA[<p>昨天解决问题的时候，用restart没有生效，没有仔细研究，今天查了下资料，有点了解了。</p>
<p>stop是杀掉所有apache进程，start是启动apache进程，这点没有疑问，但是restart不等同于stop+<a href="http://ourapache.com/archives/tag/start" class="st_tag internal_tag" rel="tag" title="标签 start 下的日志">start</a></p>
<p>执行restart，只是发送SIGHUP信号，apache会杀掉所有子进程，但是父进程不关闭，apache只是重新载入配置文件和打开日志文件，然后重新生成一系列子进程。</p>
<p>另外发现了一个有趣的参数：<a href="http://ourapache.com/archives/tag/graceful" class="st_tag internal_tag" rel="tag" title="标签 graceful 下的日志">graceful</a>，使用这个参数会发送IGUSER1信号，引起主进程处理并警告收到当前请求之后的子进程结束(或在它们不做任何服务时立刻结束)，主进程将重新读取它的配置文件并打开它的日志文件，当每一个子进程结束后,主进程将使用配置信息产生一个新的子进程来立刻响应请求并为之服务。另外当配置文件有错误的时候，父进程退出，但是子进程会继续保持连接，知道子进程处理完毕（当重启服务器的时候会引起问题，端口被占用）</p>
<p>详细信息可见apache官方文档 <a href="http://httpd.apache.org/docs/2.0/stopping.html" target="_blank">http://httpd.apache.org/docs/2.0/stopping.html</a></p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年02月6号 -- <a href="http://ourapache.com/archives/76" title="Apache 模块说明">Apache 模块说明</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/94" title="使用gzip压缩来压缩网页之apache的相关配置">使用gzip压缩来压缩网页之apache的相关配置</a></li><li>2009年02月11号 -- <a href="http://ourapache.com/archives/130" title="实时跟踪log变化的工具Apachetop">实时跟踪log变化的工具Apachetop</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/89" title="Apache PHP利用HTTP缓存协议原理解析及应用">Apache PHP利用HTTP缓存协议原理解析及应用</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/104" title="Apache和IIS共享80端口的四个方法">Apache和IIS共享80端口的四个方法</a></li><li>2009年02月27号 -- <a href="http://ourapache.com/archives/211" title="Apache common-pool, common-dbcp源码解读与对象池原理剖析">Apache common-pool, common-dbcp源码解读与对象池原理剖析</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/163" title="apache 的mime.types文件">apache 的mime.types文件</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/graceful" title="graceful" rel="tag">graceful</a>, <a href="http://ourapache.com/archives/tag/restart" title="restart" rel="tag">restart</a>, <a href="http://ourapache.com/archives/tag/start" title="start" rel="tag">start</a>, <a href="http://ourapache.com/archives/tag/stop" title="stop" rel="tag">stop</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/265/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>16个简单实用的.htaccess小贴示</title>
		<link>http://ourapache.com/archives/259</link>
		<comments>http://ourapache.com/archives/259#comments</comments>
		<pubDate>Mon, 15 Jun 2009 10:02:02 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=259</guid>
		<description><![CDATA[.htaccess 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件，对于这个文件，Apache有一堆参数可以让你配置出几乎随心所欲的功能。.htaccess 配置文件坚持了Unix的一个文化——使用一个ASCII 的纯文本文件来配置你的网站的访问策略。

这篇文章包括了16个非常有用的小技巧。另外，因为.htaccess 是一个相当强大的配置文件，所以，一个轻微的语法错误会造成你整个网站的故障，所以，在你修改或是替换原有的文件时，一定要备份旧的文件，以便出现问题的时候可以方便的恢复。]]></description>
			<content:encoded><![CDATA[<p>.<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件，对于这个文件，Apache有一堆参数可以让你配置出几乎随心所欲的功能。.<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a> 配置文件坚持了Unix的一个文化——使用一个ASCII 的纯文本文件来配置你的网站的访问策略。</p>
<p>这篇文章包括了16个非常有用的小技巧。另外，因为.htaccess 是一个相当强大的配置文件，所以，一个轻微的语法错误会造成你整个网站的故障，所以，在你修改或是替换原有的文件时，一定要备份旧的文件，以便出现问题的时候可以方便的恢复。</p>
<p><strong>1. 使用.htaccess 创建自定义的出错页面。对于Linux Apache来说这是一项极其简单的事情。使用下面的.htaccess语法你可以轻松的完成这一功能。（把.htaccess放在你的网站根目录下）</strong></p>
<blockquote><p>ErrorDocument 401 /error/401.<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a><br />
ErrorDocument 403 /error/403.php<br />
ErrorDocument 404 /error/404.php<br />
ErrorDocument 500 /error/500.php</p></blockquote>
<p><strong>2. 设置网站的时区</strong></p>
<blockquote><p>SetEnv TZ America/Houston</p></blockquote>
<p><strong>3. 阻止IP列表</strong><br />
有些时候，你需要以IP地址的方式阻止一些访问。无论是对于一个IP地址还是一个网段，这都是一件非常简单的事情，如下所示：</p>
<blockquote><p>allow from all<br />
deny from 145.186.14.122<br />
deny from 124.15</p></blockquote>
<p>Apache对于被拒绝的IP会返回403错误。</p>
<p><strong>4. 把一些老的链接转到新的链接上——搜索引擎优化SEO</strong></p>
<blockquote><p>Redirect <a href="http://ourapache.com/archives/tag/301" class="st_tag internal_tag" rel="tag" title="标签 301 下的日志">301</a> /d/file.html http://www.htaccesselite.com/r/file.html</p></blockquote>
<p><strong>5. 为服务器管理员设置电子邮件。</strong></p>
<blockquote><p>ServerSignature EMail<br />
SetEnv SERVER_ADMIN default@domain.com</p></blockquote>
<p><strong>6. 使用.htaccess 访止盗链。如果你网站上的一个图片被别的N多的网站引用了，那么，这很有可能会导致你服务器的性能下降，使用下面的代码可以保护某些热门的链接不被过多的引用。</strong></p>
<blockquote><p>Options +FollowSymlinks<br />
# Protect Hotlinking<br />
RewriteEngine On<br />
RewriteCond %{HTTP_REFERER} !^$<br />
RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]<br />
RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc]</p></blockquote>
<p><strong>7. 阻止 User Agent 的所有请求</strong></p>
<blockquote><p>## .htaccess Code :: BEGIN<br />
## Block Bad Bots by user-Agent<br />
SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]<br />
SetEnvIfNoCase user-Agent ^Java.* [NC,OR]<br />
SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]<br />
SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]<br />
SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]<br />
SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]<br />
SetEnvIfNoCase user-Agent ^Zeus [NC]</p>
<p>Order Allow,Deny<br />
Allow from all<br />
Deny from env=bad_bot</p>
<p>## .htaccess Code :: END</p></blockquote>
<p><strong>8. 把某些特殊的IP地址的请求重定向到别的站点</strong></p>
<blockquote><p>ErrorDocument 403 http://www.youdomain.com<br />
Order deny,allow<br />
Deny from all<br />
Allow from ip<br />
Allow from ip</p></blockquote>
<p><strong>9. 直接找开文件而不是下载 – 通常，我们打开网上文件的时候总是会出现一个对话框问我们是下载还是直接打开，使用下面的设置就不会出现这个问题了，直接打开</strong>。</p>
<blockquote><p>AddType application/octet-stream .pdf<br />
AddType application/octet-stream .zip<br />
AddType application/octet-stream .mov</p></blockquote>
<p><strong>10. 修改文件类型 – 下面的示例可以让任何的文件都成为PHP那么被服务器解释。比如：myphp, cgi，phtml等。</strong></p>
<blockquote><p>ForceType application/x-httpd-php<br />
SetHandler application/x-httpd-php</p></blockquote>
<p><strong>11. 阻止存取.htaccess 文件</strong></p>
<blockquote><p># secure htaccess file<br />
order allow,deny<br />
deny from all</p></blockquote>
<p><strong>12. 保护服务器上的文件被存取</strong></p>
<blockquote><p># prevent access of a certain file order allow,deny<br />
deny from all</p></blockquote>
<p><strong>13. 阻止目录浏览</strong></p>
<blockquote><p># disable directory browsing<br />
Options All -Indexes</p></blockquote>
<p><strong>14. 设置默认主页</strong></p>
<blockquote><p># serve alternate default index page<br />
DirectoryIndex about.html</p></blockquote>
<p><strong>15. 口令认证 – 你可以创建一个文件用于认证。下面是一个示例：</strong></p>
<blockquote><p># to protect a file</p>
<p>AuthType Basic<br />
AuthName “Prompt”<br />
AuthUserFile /home/path/.htpasswd<br />
Require valid-user</p>
<p># password-protect a directory<br />
resides<br />
AuthType basic<br />
AuthName “This directory is protected”<br />
AuthUserFile /home/path/.htpasswd<br />
AuthGroupFile /dev/null<br />
Require valid-user</p></blockquote>
<p><strong>16. 把老的域名转像新的域名</strong></p>
<blockquote><p># redirect from old domain to new domain<br />
RewriteEngine On<br />
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]</p></blockquote>
<p>标签: <a rel="external" href="http://www.wopus.org/tag/htaccess"><span style="color: #004499;">.htaccess</span></a></p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/316" title="htaccess二级目录重写找不到路径">htaccess二级目录重写找不到路径</a></li><li>2009年12月12号 -- <a href="http://ourapache.com/archives/310" title=".htaccess的301跳转">.htaccess的301跳转</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/32" title="htaccess学习笔记">htaccess学习笔记</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/25" title="Apache服务器使用.htaccess实现图片防盗链方法教程">Apache服务器使用.htaccess实现图片防盗链方法教程</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/htaccess" title="htaccess" rel="tag">htaccess</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/259/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>常见的rewrite规则大全</title>
		<link>http://ourapache.com/archives/255</link>
		<comments>http://ourapache.com/archives/255#comments</comments>
		<pubDate>Sun, 14 Jun 2009 02:57:43 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=255</guid>
		<description><![CDATA[常见的rewrite规则大全]]></description>
			<content:encoded><![CDATA[<table border="1">
<tbody>
<tr>
<td>目标</td>
<td>重写设置</td>
<td>说明</td>
</tr>
<tr>
<td>规范化URL</td>
<td>RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]</td>
<td>将/~user重写为/u/user的形式</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]</td>
<td>将/u/user末尾漏掉的/补上</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>规范化HostName</td>
<td>RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]</td>
<td>域名不合格</td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_HOST} !^$</td>
<td>不空</td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{SERVER_PORT} !^80$</td>
<td>不是80端口</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]</td>
<td>重写</td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_HOST} !^$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>URL根目录转移</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/$ /e/www/ [R]</td>
<td>从/移到/e/www/</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>末尾目录补斜线</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td>（目录范围内）</td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo$ foo/ [R]</td>
<td>/~quux/foo是一个目录，补/</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REQUEST_FILENAME} -d</td>
<td>如果请文件名是个目录</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+[^/])$ $1/ [R]</td>
<td>URL末尾不是斜线时补上</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Web集群</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteMap user-to-host txt:/path/to/map.user-to-host</td>
<td>用户－服务器映射</td>
</tr>
<tr>
<td> </td>
<td>RewriteMap group-to-host txt:/path/to/map.group-to-host</td>
<td>组－服务器映射</td>
</tr>
<tr>
<td> </td>
<td>RewriteMap entity-to-host txt:/path/to/map.entity-to-host</td>
<td>实体－服务器映射</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/u/([^/]+)/?(.*) http://${user-to-host:$1|server0}/u/$1/$2</td>
<td>用户均衡</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/g/([^/]+)/?(.*) http://${group-to-host:$1|server0}/g/$1/$2</td>
<td>组均衡</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2</td>
<td>实体均衡</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/([uge])/([^/]+)/?$ /$1/$2/.www/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/([uge])/([^/]+)/([^.]+.+) /$1/$2/.www/$3\</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>URL根目录搬迁</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/~(.+) http://newserver/~$1 [R,L]</td>
<td>到其它服务器</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>所用户名首字母分</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3</td>
<td>内一层括号为$2</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>NCSA imagemap移</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td>植为mod_imap</td>
<td>RewriteRule ^/cgi-bin/imagemap(.*) $1 [PT]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>多目录查找资源</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># first try to find it in custom/&#8230;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+) /your/docroot/dir1/$1 [L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># second try to find it in pub/&#8230;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+) /your/docroot/dir2/$1 [L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># else go on for other Alias or ScriptAlias directives,</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+) &#8211; [PT]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>据URL设置环境变量</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.*)/S=([^/]+)/(.*) $1/$3 [E=STATUS:$2]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>虚拟主机</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$</td>
<td>基于用户名</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+) %{HTTP_HOST}$1 [C]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>内外人有别</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$</td>
<td>基于远程主机</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>错误重定向</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f</td>
<td>不是regular文件</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.+) http://webserverB.dom/$1</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>程序处理特殊协议</td>
<td>RewriteRule ^xredirect:(.+) /path/to/nph-xredirect.cgi/$1 \</td>
<td>Xredirect协议</td>
</tr>
<tr>
<td> </td>
<td>[T=application/x-httpd-cgi,L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>最近镜像下载</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteMap multiplex txt:/path/to/map.cxan</td>
<td>顶级域名与最近ftp服务器映射</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/CxAN/(.*) %{REMOTE_HOST}::$1 [C]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^.+\.([a-zA-Z]+)::(.*)$ ${multiplex:$1|ftp.default.dom}$2 [R,L]</td>
<td>据顶级域名不同提供不同的FTP服务器</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>基于时间重写</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{TIME_HOUR}%{TIME_MIN} &gt;0700</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{TIME_HOUR}%{TIME_MIN} &lt;1900</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.day.html</td>
<td>白天为早晚7点间</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.night.html</td>
<td>其余为夜间</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>向前兼容扩展名</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># parse out basename, but remember the fact</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># <a href="http://ourapache.com/archives/tag/rewrite" class="st_tag internal_tag" rel="tag" title="标签 rewrite 下的日志">rewrite</a> to document.phtml if exists</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REQUEST_FILENAME}.phtml -f</td>
<td>如果存在$1.phtml则重写</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.*)$ $1.phtml [S=1]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td># else reverse the previous basename cutout</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{ENV:WasHTML} ^yes$</td>
<td>如果不存在$1.phtml，则保持不变</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^(.*)$ $1.html</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>文件改名（目录级）</td>
<td>RewriteEngine on</td>
<td>内部重写</td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ bar.html</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteEngine on</td>
<td>重定向由客户端再次提交</td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ bar.html [R]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>据浏览器类型重写</td>
<td>RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.NS.html [L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.20.html [L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.32.html [L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>动态镜像远程资源</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1 [P]</td>
<td>利用了代理模块</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^usa-news\.html$ http://www.quux-corp.com/news/index.html [P]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>反向动态镜像</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond /mirror/of/remotesite/$1 -U</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>负载均衡</td>
<td>RewriteEngine on</td>
<td>利用代理实现round-robin效果</td>
</tr>
<tr>
<td> </td>
<td>RewriteMap lb prg:/path/to/lb.pl</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/(.+)$ ${lb:$1} [P,L]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>#!/path/to/perl</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$| = 1;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$name = “www”; # the hostname base</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$first = 1; # the first server (not 0 here, because 0 is myself)</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$last = 5; # the last server in the round-robin</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$domain = “foo.dom”; # the domainname</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$cnt = 0;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>while (&lt;STDIN&gt;) {</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$cnt = (($cnt+1) % ($last+1-$first));</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$server = sprintf(“%s%d.%s”, $name, $cnt+$first, $domain);</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>print “http://$server/$_”;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>}</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>##EOF##</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>静态页面变脚本</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteBase /~quux/</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>阻击机器人</td>
<td>RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/~quux/foo/arc/.+ &#8211; [F]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>阻止盗连你的图片</td>
<td>RewriteCond %{HTTP_REFERER} !^$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]</td>
<td>自己的连接可不能被阻止</td>
</tr>
<tr>
<td> </td>
<td>RewriteRule .*\.gif$ &#8211; [F]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_REFERER} !^$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^inlined-in-foo\.gif$ &#8211; [F]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>拒绝某些主机访问</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteMap hosts-deny txt:/path/to/hosts.deny</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/.* &#8211; [F]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>用户授权</td>
<td>RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend1@client1.quux-corp\.com$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp\.com$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp\.com$</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/~quux/only-for-friends/ &#8211; [F]</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>外部重写程序模板</td>
<td>RewriteEngine on</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteMap quux-map prg:/path/to/map.quux.pl</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>#!/path/to/perl</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>$| = 1;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>while (&lt;&gt;) {</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>s|^foo/|bar/|;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>print $_;</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>}</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>搜索引擎友好</td>
<td>RewriteRule ^/products$ /content.<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/products/([0-9]+)$ /content.php?id=$1</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>RewriteRule ^/products/([0-9]+),([ad]*),([0-9]{0,3}),([0-9]*),([0-9]*$) /marso/content.php?id=$1&amp;sort=$2&amp;order=$3&amp;<a href="http://ourapache.com/archives/tag/start" class="st_tag internal_tag" rel="tag" title="标签 start 下的日志">start</a>=$4</td>
</tr>
</tbody>
</table>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月16号 -- <a href="http://ourapache.com/archives/140" title="Apache、resin、rewrite泛域名、多域名设置">Apache、resin、rewrite泛域名、多域名设置</a></li><li>2009年02月12号 -- <a href="http://ourapache.com/archives/136" title="让apache支持自定义404页面错误">让apache支持自定义404页面错误</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/106" title="Apache Rewrite 规则详解">Apache Rewrite 规则详解</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/rewrite" title="rewrite" rel="tag">rewrite</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/255/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache自动添加地址末尾的斜线</title>
		<link>http://ourapache.com/archives/253</link>
		<comments>http://ourapache.com/archives/253#comments</comments>
		<pubDate>Sun, 14 Jun 2009 02:55:52 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=253</guid>
		<description><![CDATA[我们都知道，在windows下的apache系统在访问网址时，最后的地址是个目录，apache系统能够自动加个/线，而Linux下的apache不能自动加。]]></description>
			<content:encoded><![CDATA[<p>　　我们都知道，在windows下的apache系统在访问网址时，最后的地址是个目录，apache系统能够自动加个/线，而Linux下的apache不能自动加。</p>
<p>例如：</p>
<p>http://biweb.cn/bbs</p>
<p>转换为</p>
<p>http://biweb.cn/bbs/</p>
<p>在windows下是可以自动转换的，但是在liunx下或者UNix下是不行的，或报404错误。</p>
<p>那么我们怎么在liunx下修正这个问题呢。只需要在apache的httpd.conf中加入下面的代码，前提是<br />
LoadModule <a href="http://ourapache.com/archives/tag/rewrite" class="st_tag internal_tag" rel="tag" title="标签 rewrite 下的日志">rewrite</a>_module modules/mod_<a href="http://ourapache.com/archives/tag/rewrite" class="st_tag internal_tag" rel="tag" title="标签 rewrite 下的日志">rewrite</a>.so要打开。<br />
代码如下：<br />
RewriteEngine On<br />
RewriteCond %{REQUEST_FILENAME} -d<br />
RewriteRule ^(.+[^/])$ $1/ [R]</p>
<p>加入之后，重启apache，就可以正常访问了。是不是挺方便？</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月13号 -- <a href="http://ourapache.com/archives/270" title="Apache配置之URL重写">Apache配置之URL重写</a></li><li>2009年02月12号 -- <a href="http://ourapache.com/archives/134" title="泛域名与mod_rewrite">泛域名与mod_rewrite</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/mod_rewrite" title="mod_rewrite" rel="tag">mod_rewrite</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/253/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apxs是Apache编译和安装扩展模块的工具</title>
		<link>http://ourapache.com/archives/251</link>
		<comments>http://ourapache.com/archives/251#comments</comments>
		<pubDate>Sun, 07 Jun 2009 11:28:35 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[apxs]]></category>
		<category><![CDATA[扩展]]></category>
		<category><![CDATA[编译]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=251</guid>
		<description><![CDATA[apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具，用于编译一个或多个源程序或目标代码文件为动态共享对象，使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。

因此，要使用这个扩展机制，你的平台必须支持DSO特性，而且Apache httpd必须内建了mod_so模块。]]></description>
			<content:encoded><![CDATA[<p>apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具，用于编译一个或多个源程序或目标代码文件为动态共享对象，使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。</p>
<p>因此，要使用这个扩展机制，你的平台必须支持DSO特性，而且Apache httpd必须内建了mod_so模块。apxs工具能自动探测是否具备这样的条件，你也可以自己用这个命令手动探测：</p>
<p>$ httpd -l</p>
<p>该命令的输出列表中应该有mod_so模块。如果所有这些条件均已具备，则可以很容易地借助apxs安装你自己的DSO模块以扩展Apache服务器的功能：</p>
<blockquote><p>$ <a href="http://ourapache.com/archives/tag/apxs" class="st_tag internal_tag" rel="tag" title="标签 apxs 下的日志">apxs</a> -i -a -c mod_foo.c<br />
gcc -fpic -DSHARED_MODULE -I/path/to/apache/include -c mod_foo.c<br />
ld -Bshareable -o mod_foo.so mod_foo.o<br />
cp mod_foo.so /path/to/apache/modules/mod_foo.so<br />
chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/etc/httpd.conf]<br />
$ apachectl <a href="http://ourapache.com/archives/tag/restart" class="st_tag internal_tag" rel="tag" title="标签 restart 下的日志">restart</a><br />
/path/to/apache/sbin/apachectl restart: httpd not running, trying to <a href="http://ourapache.com/archives/tag/start" class="st_tag internal_tag" rel="tag" title="标签 start 下的日志">start</a><br />
[Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
/path/to/apache/sbin/apachectl restart: httpd started<br />
$ _</p></blockquote>
<p>其中的参数files可以是任何C源程序文件(.c)、目标代码文件(.o)、甚至是一个库(.a)。apxs工具会根据其后缀自动编译C源程序或者连接目标代码和库。但是，使用预编译的目标代码时，必须保证它们是地址独立代码(PIC)，使之能被动态地加载。如果使用GCC编译，则应该使用 -fpic 参数；如果使用其他C编译器，则应该查阅其手册，为apxs使用相应的编译参数。</p>
<p>有关Apache对DSO的支持的详细信息，可以阅读mod_so文档，或者直接阅读src/modules/standard/mod_so.c源程序。</p>
<p>语法</p>
<blockquote><p>apxs -g [ -S name=value ] -n modname</p>
<p>apxs -q [ -S name=value ] query &#8230;</p>
<p>apxs -c [ -S name=value ] [ -o dsofile ] [ -I incdir ] [ -D name=value ] [ -L libdir ] [ -l libname ] [ -Wc,compiler-flags ] [ -Wl,linker-flags ] files &#8230;</p>
<p>apxs -i [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file &#8230;</p>
<p>apxs -e [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file &#8230;</p></blockquote>
<p>选项<br />
一般选项<br />
-n modname<br />
它明确设置了 -i(安装)和 -g(模板生成)选项的模块名称。对 -g 选项，它是必须的；对 -i 选项，apxs工具会根据源代码判断，或(在失败的情况下)按文件名推测出这个模块的名称。<br />
查询选项<br />
-q<br />
查询某种apxs设置的信息。该选项的query参数可以是下列一个或多个字符串：CC, CFLAGS, CFLAGS_SHLIB, INCLUDEDIR, LD_SHLIB, LDFLAGS_SHLIB, LIBEXECDIR, LIBS_SHLIB, SBINDIR, SYSCONFDIR, TARGET 。<br />
这个参数用于手动查询某些设置。比如，要手动处理Apache的C头文件，可以在Makefile中使用：</p>
<p>INC=-I`apxs -q INCLUDEDIR`</p>
<p>配置选项<br />
-S name=value<br />
此选项可以改变apxs的上述设置。<br />
模板生成选项<br />
-g<br />
此选项生成一个名为name的子目录(见选项 -n)和其中的两个文件：一个是名为mod_name.c的样板模块源程序，可以用来建立你自己的模块，或是学习使用apxs机制的良好开端；另一个则是对应的Makefile ，用于编译和安装此模块。<br />
DSO编译选项<br />
-c<br />
此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o)，然后连接这些目标代码和files中其余的目标代码文件(.o和.a)，以生成动态共享对象dsofile 。如果没有指定 -o 选项，则此输出文件名由files中的第一个文件名推测得到，也就是默认为mod_name.so 。<br />
-o dsofile<br />
明确指定所建立的动态共享对象的文件名，它不能从files文件列表中推测得到。如果没有明确指定，则其文件名将为mod_unknown.so 。<br />
-D name=value<br />
此选项直接传递到给编译命令，用于增加自定义的编译变量。<br />
-I incdir<br />
此选项直接传递到给编译命令，用于增加自定义的包含目录。<br />
-L libdir<br />
此选项直接传递到给连接命令，用于增加自定义的库文件目录。<br />
-l libname<br />
此选项直接传递到给连接命令，用于增加自定义的库文件。<br />
-Wc,compiler-flags<br />
此选项用于向编译命令 libtool &#8211;mode=compile 中附加compiler-flags ，以增加编译器特有的选项。<br />
-Wl,linker-flags<br />
此选项用于向连接命令 libtool &#8211;mode=link 中附加linker-flags ，以增加连接器特有的选项。<br />
DSO的安装和配置选项<br />
-i<br />
此选项表示需要执行安装操作，以安装一个或多个动态共享对象到服务器的modules目录中。<br />
-a<br />
此选项自动增加一个LoadModule行到httpd.conf文件中，以激活此模块，或者，如果此行已经存在，则启用之。<br />
-A<br />
与 -a 选项类似，但是它增加的LoadModule命令有一个井号前缀(#)，即此模块已经准备就绪但尚未启用。<br />
-e<br />
表示需要执行编辑操作，它可以与 -a 和 -A 选项配合使用，与 -i 操作类似，修改Apache的httpd.conf文件，但是并不安装此模块。<br />
举例<br />
假设有一个扩展Apache功能的模块mod_foo.c ，使用下列命令，可以将C源程序编译为共享模块，以在运行时加载到Apache服务器中：</p>
<blockquote><p>$ apxs -c mod_foo.c<br />
/path/to/libtool &#8211;mode=compile gcc &#8230; -c mod_foo.c<br />
/path/to/libtool &#8211;mode=link gcc &#8230; -o mod_foo.la mod_foo.slo<br />
$ _</p></blockquote>
<p>然后，必须修改Apache的配置，以确保有一个LoadModule指令来加载此共享对象。为了简化这一步骤，apxs可以自动进行该操作，以安装此共享对象到”modules”<a href="http://ourapache.com/archives/tag/%e7%9b%ae%e5%bd%95" class="st_tag internal_tag" rel="tag" title="标签 目录 下的日志">目录</a>，并更新httpd.conf文件，命令如下：</p>
<blockquote><p>$ apxs -i -a mod_foo.la<br />
/path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
/path/to/libtool &#8211;mode=install cp mod_foo.la /path/to/apache/modules &#8230; chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/conf/httpd.conf]<br />
$ _</p></blockquote>
<p>如果配置文件中尚不存在，会增加下列的行：</p>
<p>LoadModule foo_module modules/mod_foo.so</p>
<p>如果你希望默认禁用此模块，可以使用 -A 选项，即：</p>
<p>$ apxs -i -A mod_foo.c</p>
<p>要快速测试apxs机制，可以建立一个Apache模块样板及其对应的Makefile ：</p>
<blockquote><p>$ apxs -g -n foo<br />
Creating [DIR] foo<br />
Creating [FILE] foo/Makefile<br />
Creating [FILE] foo/modules.mk<br />
Creating [FILE] foo/mod_foo.c<br />
Creating [FILE] foo/.deps<br />
$ _</p></blockquote>
<p>然后，立即可以编译此样板模块为共享对象并加载到Apache服务器中：</p>
<blockquote><p>$ cd foo<br />
$ make all reload<br />
apxs -c mod_foo.c<br />
/path/to/libtool &#8211;mode=compile gcc &#8230; -c mod_foo.c<br />
/path/to/libtool &#8211;mode=link gcc &#8230; -o mod_foo.la mod_foo.slo<br />
apxs -i -a -n “foo” mod_foo.la<br />
/path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
/path/to/libtool &#8211;mode=install cp mod_foo.la /path/to/apache/modules &#8230; chmod 755 /path/to/apache/modules/mod_foo.so<br />
[activating module 'foo' in /path/to/apache/conf/httpd.conf]<br />
apachectl restart<br />
/path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
[Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
/path/to/apache/sbin/apachectl restart: httpd started<br />
$ _</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2008年12月27号 -- <a href="http://ourapache.com/archives/11" title="apxs &#8211; Apache 扩展工具">apxs &#8211; Apache 扩展工具</a></li><li>2009年08月13号 -- <a href="http://ourapache.com/archives/286" title="linux下查看nginx，apache，mysql，php的编译参数">linux下查看nginx，apache，mysql，php的编译参数</a></li><li>2009年02月17号 -- <a href="http://ourapache.com/archives/142" title="在64位机器上关于Apache 2.2.3版的编译问题">在64位机器上关于Apache 2.2.3版的编译问题</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/13" title="单独编译apache的rewrite模块">单独编译apache的rewrite模块</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/apxs" title="apxs" rel="tag">apxs</a>, <a href="http://ourapache.com/archives/tag/%e6%89%a9%e5%b1%95" title="扩展" rel="tag">扩展</a>, <a href="http://ourapache.com/archives/tag/%e7%bc%96%e8%af%91" title="编译" rel="tag">编译</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/251/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache的prefork模式和worker模式</title>
		<link>http://ourapache.com/archives/234</link>
		<comments>http://ourapache.com/archives/234#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:13:59 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[prefork]]></category>
		<category><![CDATA[worker]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=234</guid>
		<description><![CDATA[Apache的prefork模式和worker模式]]></description>
			<content:encoded><![CDATA[<p><strong>prefork模式</strong></p>
<p>这个多路处理模块(MPM)实现了一个非线程型的、预派生的web服务器，它的工作方式类似于Apache 1.3。它适合于没有线程安全库，需要避免线程兼容性问题的系统。它是要求将每个请求相互独立的情况下最好的MPM，这样若一个请求出现问题就不会影响到其他请求。</p>
<p>这个MPM具有很强的自我调节能力，只需要很少的配置指令调整。最重要的是将MaxClients设置为一个足够大的数值以处理潜在的请求高峰，同时又不能太大，以致需要使用的内存超出物理内存的大小。</p>
<p><strong>worker模式</strong></p>
<p>此多路处理模块(MPM)使网络服务器支持混合的多线程多进程。由于使用线程来处理请求，所以可以处理海量请求，而系统资源的开销小于基于进程的MPM。但是，它也使用了多进程，每个进程又有多个线程，以获得基于进程的MPM的稳定性。</p>
<p>控制这个MPM的最重要的指令是，控制每个子进程允许建立的线程数的ThreadsPerChild指令，和控制允许建立的总线程数的MaxClients指令。</p>
<p> </p>
<p><strong>prefork和worker模式的切换</strong></p>
<p>1.将当前的prefork模式启动文件改名<br />
mv httpd httpd.<a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a></p>
<p>2.将worker模式的启动文件改名<br />
mv httpd.<a href="http://ourapache.com/archives/tag/worker" class="st_tag internal_tag" rel="tag" title="标签 worker 下的日志">worker</a> httpd</p>
<p>3.修改Apache配置文件<br />
vi /usr/local/apache2/conf/extra/httpd-mpm.conf</p>
<p>找到里边的如下一段，可适当修改负载等参数：</p>
<blockquote><p>&lt;IfModule mpm_prefork_module&gt;<br />
ServerLimit 256<br />
StartServers 5<br />
MinSpareServers 5<br />
MaxSpareServers 10<br />
MaxClients 256<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</p></blockquote>
<p>4.重新启动服务<br />
/usr/local/apache2/bin/apachectl <a href="http://ourapache.com/archives/tag/restart" class="st_tag internal_tag" rel="tag" title="标签 restart 下的日志">restart</a></p>
<p>即可换成worker方式启动apache2</p>
<p>处于稳定性和安全性考虑，不建议更换apache2的运行方式，使用系统默认prefork即可。另外很多php模块不能工作在worker模式下，例如redhat linux自带的php也不能支持线程安全。所以最好不要切换工作模式。</p>
<p><strong>prefork和worker模式的比较</strong></p>
<p>prefork模式使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。在大多数平台上，Prefork MPM在效率上要比Worker MPM要高，但是内存使用大得多。prefork的无线程设计在某些情况下将比worker更有优势：它可以使用那些没有处理好线程安全的第三方模块，并且对于那些线程调试困难的平台而言，它也更容易调试一些。</p>
<p>worker模式使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。通常来说，在一个高流量的HTTP服务器上，Worker MPM是个比较好的选择，因为Worker MPM的内存使用比Prefork MPM要低得多。但worker MPM也由不完善的地方，如果一个线程崩溃，整个进程就会连同其所有线程一起”死掉”.由于线程共享内存空间，所以一个程序在运行时必须被系统识别为”每个线程都是安全的”。</p>
<p>总的来说，prefork方式速度要稍高于worker，然而它需要的cpu和memory资源也稍多于woker。</p>
<p><strong>prefork模式配置详解</strong></p>
<blockquote><p>&lt;IfModule mpm_prefork_module&gt;<br />
ServerLimit 256<br />
StartServers 5<br />
MinSpareServers 5<br />
MaxSpareServers 10<br />
MaxClients 256<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</p></blockquote>
<p>ServerLimit<br />
默认的MaxClient最大是256个线程,如果想设置更大的值，就的加上ServerLimit这个参数。20000是ServerLimit这个参数的最大值。如果需要更大，则必须编译apache,此前都是不需要重新编译Apache。<br />
生效前提：必须放在其他指令的前面</p>
<p>StartServers<br />
指定服务器启动时建立的子进程数量，prefork默认为5。</p>
<p>MinSpareServers<br />
指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。</p>
<p>MaxSpareServers<br />
设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成”MinSpareServers+1″。</p>
<p>MaxClients<br />
限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为256。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit。</p>
<p>MaxRequestsPerChild<br />
每个子进程在其生存期内允许伺服的最大请求数量，默认为10000.到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0″，子进程将永远不会结束。将MaxRequestsPerChild设置成非零值有两个好处：<br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</p>
<p><strong>worker模式配置详解</strong></p>
<blockquote><p>&lt;IfModule mpm_worker_module&gt;<br />
StartServers 2<br />
MaxClients 150<br />
MinSpareThreads 25<br />
MaxSpareThreads 75<br />
ThreadsPerChild 25<br />
MaxRequestsPerChild 0<br />
&lt;/IfModule&gt;</p></blockquote>
<p>StartServers<br />
服务器启动时建立的子进程数，默认值是”3″。</p>
<p>MaxClients<br />
允许同时伺服的最大接入请求数量(最大线程数量)。任何超过MaxClients限制的请求都将进入等候队列。默认值是”400″,16(ServerLimit)乘以25(ThreadsPerChild)的结果。因此要增加MaxClients的时候，你必须同时增加ServerLimit的值。</p>
<p>MinSpareThreads<br />
最小空闲线程数,默认值是”75″。这个MPM将基于整个服务器监视空闲线程数。如果服务器中总的空闲线程数太少，子进程将产生新的空闲线程。</p>
<p>MaxSpareThreads<br />
设置最大空闲线程数。默认值是”250″。这个MPM将基于整个服务器监视空闲线程数。如果服务器中总的空闲线程数太多，子进程将杀死多余的空闲线程。MaxSpareThreads的取值范围是有限制的。Apache将按照如下限制自动修正你设置的值：worker要求其大于等于MinSpareThreads加上ThreadsPerChild的和。</p>
<p>ThreadsPerChild<br />
每个子进程建立的常驻的执行线程数。默认值是25。子进程在启动时建立这些线程后就不再建立新的线程了。</p>
<p>MaxRequestsPerChild<br />
设置每个子进程在其生存期内允许伺服的最大请求数量。到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0″，子进程将永远不会结束。将MaxRequestsPerChild设置成非零值有两个好处：<br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。<br />
注意对于KeepAlive链接，只有第一个请求会被计数。事实上，它改变了每个子进程限制最大链接数量的行为。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/232" title="Apache Prefork和Worker模式的性能比较测试">Apache Prefork和Worker模式的性能比较测试</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/222" title="Apache 2.0中prefork.c模块和worker.c模块的比较">Apache 2.0中prefork.c模块和worker.c模块的比较</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/229" title="对Apache中并发控制参数prefork理解和调优">对Apache中并发控制参数prefork理解和调优</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/62" title="对apache中并发控制参数prefork理解和调优">对apache中并发控制参数prefork理解和调优</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a>, <a href="http://ourapache.com/archives/tag/worker" title="worker" rel="tag">worker</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/234/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>对Apache中并发控制参数prefork理解和调优</title>
		<link>http://ourapache.com/archives/229</link>
		<comments>http://ourapache.com/archives/229#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:03:00 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[prefork]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=229</guid>
		<description><![CDATA[一个apache有linux下的并发不是很高的,大约到3K的样子(其实处理的http的请求可能只有300/s),普通的服务器都会不同程度的出现问题.apache有关并发控制主要是 prefork和worker二个其中一个来控制.我们可以使用httpd -l来确定当前使用的MPM是prefork.c,还是Worker.c.下面是apache中有关prefork的配置.下面是我优化过的参数.]]></description>
			<content:encoded><![CDATA[<p>一个apache有linux下的并发不是很高的,大约到3K的样子(其实处理的http的请求可能只有300/s),普通的服务器都会不同程度的出现问题.apache有关并发控制主要是 prefork和worker二个其中一个来控制.我们可以使用httpd -l来确定当前使用的MPM是prefork.c,还是Worker.c.下面是apache中有关prefork的配置.下面是我优化过的参数.</p>
<p>&lt;IfModule <a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a>.c&gt;</p>
<p>#有这个参数就不必像apache1一样修改源码才能修改256客户数的限制,听讲要放到最前面才会生效,2000是这个参数的最大值<br />
ServerLimit 2000<br />
#指定服务器启动时建立的子进程数量，prefork默认为5。<br />
StartServers 25</p>
<p>#指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。<br />
MinSpareServers 25</p>
<p>#设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数 不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成”MinSpareServers+1&#8243;。<br />
MaxSpareServers 50</p>
<p>#限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为256。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit 。<br />
MaxClients 2000</p>
<p>#每个子进程在其生存期内允许伺服的最大请求数量，默认为10000.到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为”0&#8243;，子进程将永远不会结束。<br />
MaxRequestsPerChild 10000</p>
<p>&lt;/IfModule&gt;</p>
<p>将MaxRequestsPerChild设置成非零值有两个好处：<br />
1.可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。<br />
2.给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</p>
<p>工作方式：<br />
一个单独的控制进程(父进程)负责产生子进程，这些子进程用于监听请求并作出应答。Apache总是试图保持一些备用的 (spare)或者是空闲的子进程用于迎接即将到来的请求。这样客户端就不需要在得到服务前等候子进程的产生。在Unix系统中，父进程通常以root身 份运行以便邦定80端口，而 Apache产生的子进程通常以一个低特权的用户运行。User和Group指令用于设置子进程的低特权用户。运行子进程的用户必须要对它所服务的内容有 读取的权限，但是对服务内容之外的其他资源必须拥有尽可能少的权限。</p>
<p><span style="color: #ff6600;">对上面的有些值，一定要记的不是越大越好.这个需要经过几次尝试和出错之后才能选好要使用的值(不同的硬件处理水平不一样)。最重要的值是maxclient允许足够多的 工作进程，同时又不会导致服务器进行过度的交换(死机)。如果传入的请求超出处理能力而让服务器当掉的话，那么至少满足此值的那些请求会得到服务，其他请求被阻塞这样会更加好。</span></p>
<p> </p>
<p><strong>我们调优常常要查看httpd进程数（即prefork模式下Apache能够处理的并发请求数）</strong>：</p>
<p>#ps -ef | grep httpd | wc -l</p>
<p>出现的结果,就是当前Apache能够处理的多少个并发请求，这个值Apache根据负载情况自动调.</p>
<p><strong>查看Apache的并发请求数及其TCP连接状态： </strong></p>
<p>#netstat -n | awk &#8216;/^<a href="http://ourapache.com/archives/tag/tcp" class="st_tag internal_tag" rel="tag" title="标签 tcp 下的日志">tcp</a>/ {++S[$NF]} END {for(a in S) print a, S[a]}&#8217;</p>
<p>上面这句来自己我一个新浪的朋友<a href="http://blog.s135.com/"><span style="color: #729752;">张宴</span></a>.</p>
<p>返回结果示例：<br />
LAST_ACK 5<br />
SYN_RECV 30<br />
ESTABLISHED 1597<br />
FIN_WAIT1 51<br />
FIN_WAIT2 504<br />
TIME_WAIT 1057<br />
其中的SYN_RECV表示正在等待处理的请求数；ESTABLISHED表示正常数据传输状态；TIME_WAIT表示处理完毕，等待超时结束的请求数。</p>
<p><a href="http://ourapache.com/archives/tag/%e7%8a%b6%e6%80%81" class="st_tag internal_tag" rel="tag" title="标签 状态 下的日志">状态</a>：描述<br />
CLOSED：无连接是活动的或正在进行<br />
LISTEN：服务器在等待进入呼叫<br />
SYN_RECV：一个连接请求已经到达，等待确认<br />
SYN_SENT：应用已经开始，打开一个连接<br />
ESTABLISHED：正常数据传输状态<br />
FIN_WAIT1：应用说它已经完成<br />
FIN_WAIT2：另一边已同意释放<br />
ITMED_WAIT：等待所有分组死掉<br />
CLOSING：两边同时尝试关闭<br />
TIME_WAIT：另一边已初始化一个释放<br />
LAST_ACK：等待所有分组死掉</p>
<p>可以使用<span style="font-family: 宋体;">Linux下的webbench来作压力测试.</span></p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年08月16号 -- <a href="http://ourapache.com/archives/288" title="Apache两种常用工作模式比较:prefork和worker">Apache两种常用工作模式比较:prefork和worker</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/234" title="Apache的prefork模式和worker模式">Apache的prefork模式和worker模式</a></li><li>2009年03月30号 -- <a href="http://ourapache.com/archives/232" title="Apache Prefork和Worker模式的性能比较测试">Apache Prefork和Worker模式的性能比较测试</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/222" title="Apache 2.0中prefork.c模块和worker.c模块的比较">Apache 2.0中prefork.c模块和worker.c模块的比较</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/64" title="Apache连接数设置prefork">Apache连接数设置prefork</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/62" title="对apache中并发控制参数prefork理解和调优">对apache中并发控制参数prefork理解和调优</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/prefork" title="prefork" rel="tag">prefork</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/229/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache日志文件（配置和管理）</title>
		<link>http://ourapache.com/archives/184</link>
		<comments>http://ourapache.com/archives/184#comments</comments>
		<pubDate>Thu, 26 Feb 2009 04:07:19 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[日志]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=184</guid>
		<description><![CDATA[Apache日志文件（配置和管理）]]></description>
			<content:encoded><![CDATA[<p><strong>1.安全警告：</strong></p>
<p>任何人只要对Apache存放日志文件的目录具有写权限，也就当然地可以获得启动Apache的用户(通常是root)的权限，绝对不要随意给予任何人存放日志文件目录的写权限。</p>
<p><strong>2.错误日志(Error <a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">Log</a>)</strong></p>
<p>Apache httpd将在这个文件中存放诊断信息和处理请求中出现的错误，由于这里经常包含了出错细节以及如何解决，如果服务器启动或运行中有问题，首先就应该查看这个错误日志</p>
<p>错误日志通常被写入一个文件(unix系统上一般是error_log ，Windows和OS/2上一般是error.log)。在unix系统中，错误日志还可能被重定向到syslog或通过管道操作传递给一个程序。</p>
<p><strong>3.访问日志(Access Log)</strong></p>
<p>记录服务器所处理的所有请求，其文件名和位置取决于CustomLog指令，LogFormat指令可以简化日志的内容。</p>
<p>不同版本的Apache httpd使用了不同的模块和指令来控制对访问的记录，包括mod_log_referer, mod_log_agent和TransferLog指令。现在，CustomLog指令包含了旧版本中相关指令的所有功能。</p>
<p><strong>通用日志格式</strong>(Common Log Format)，下面是一个典型的记录格式：<br />
LogFormat “%h %l %u %t \\”%r\\” %&gt;s %b” common<br />
CustomLog logs/access_log common<br />
它定义了一种特定的记录格式字符串，并给它起了个别名叫common ，其中的”%”指示服务器用某种信息替换，其他字符则不作替换。引号(”)必须加反斜杠转义，以避免被解释为字符串的结束。格式字符串还可以包含特殊的控制符，如换行符”\\n” 、制表符”\\t”。<br />
CustomLog指令建立一个使用指定别名的新日志文件，除非其文件名是以斜杠开头的绝对路径，否则其路径就是相对于ServerRoot的相对路径。</p>
<p><strong>组合日志格式</strong>(Combined Log Format)，形式如下：<br />
LogFormat “%h %l %u %t \\”%r\\” %&gt;s %b \\”%{Referer}i\\” \\”%{User-agent}i\\”” combined<br />
CustomLog log/access_log combined<br />
这种格式与通用日志格式类似，但是多了两个 %{header}i 项，其中的header可以是任何请求头。</p>
<p><strong>多文件访问日志</strong>：<br />
可以简单地在配置文件中用多个CustomLog指令来建立多文件访问日志。如下例，既记录基本的CLF信息，又记录提交网页和浏览器的信息，最后两行CustomLog示范了如何模拟ReferLog和AgentLog指令的效果。<br />
LogFormat “%h %l %u %t \\”%r\\” %&gt;s %b” common<br />
CustomLog logs/access_log common<br />
CustomLog logs/referer_log “%{Referer}i -&gt; %U”<br />
CustomLog logs/agent_log “%{User-agent}i”<br />
此例也说明了，记录格式可以直接由CustomLog指定，而并不一定要用LogFormat起一个别名。</p>
<p><strong>条件日志</strong>：<br />
许多时候，根据与请求特征相关的环境变量来有选择地记录某些客户端请求会带来便利。首先，需要使用SetEnvIf指令来设置特定的环境变量以标识符合某种特定条件的请求，然后用CustomLog指令的 env= 子句，根据这些环境变量来决定记录或排除特定的请求。例如：<br />
# 不记录本机发出的请求<br />
SetEnvIf Remote_Addr “127\\.0\\.0\\.1″ dontlog<br />
# 不记录对robots.txt文件的请求<br />
SetEnvIf Request_URI “^/robots\\.txt$” dontlog<br />
# 记录其他请求<br />
CustomLog logs/access_log common env=!dontlog</p>
<p><strong>4.日志滚动</strong></p>
<p>由于Apache会保持日志文件的打开，并持续写入信息，因此服务器运行期间不能执行滚动操作。移动或者删除日志文件以后，必须重新启动服务器才能让它打开新的日志文件。</p>
<p>用优雅的(<a href="http://ourapache.com/archives/tag/graceful" class="st_tag internal_tag" rel="tag" title="标签 graceful 下的日志">graceful</a>)方法重新启动，可以使服务器启用新的日志文件，而不丢失原来尚未写入的信息。为此，有必要等待一段时间，让服务器完成正在处理的请求，并将记录写入到原来的日志文件。以下是一个典型的日志滚动和为节省存储空间而压缩旧日志的例子：<br />
mv access_log access_log.old<br />
mv error_log error_log.old<br />
apachectl graceful<br />
sleep 600<br />
gzip access_log.old error_log.old</p>
<p><strong>5.管道日志</strong></p>
<p>Apache httpd可以通过管道将访问记录和出错信息传递给另一个进程，而不是写入一个文件，由于无须对主服务器进行编程，这个功能显著地增强了日志的灵活性。只要用管道操作符”|”后面跟一个可执行文件名，就可以使这个程序从标准输入设备获得事件记录。Apache在启动时，会同时启动这个管道日志进程，并且在运行过程中，如果这个进程崩溃了，会重新启动这个进程(所以我们称这个技术为”可靠管道日志”)。</p>
<p>管道日志进程由其父进程Apache httpd产生，并继承其权限，这意味着管道进程通常是作为root运行的，所以保持这个程序简单而安全极为重要。（yes）</p>
<p>管道日志的一种重要用途是，允许日志滚动而无须重新启动服务器。为此，服务器提供了一个简单的程序rotatelogs 。每24小时滚动一次日志的例子如下：<br />
CustomLog “|/usr/local/apache/bin/rotatelogs /var/log/access_log 86400″ common<br />
注意：引号用于界定整个管道命令行。虽然这是针对访问日志的，但是其用法对于其他日志也一样。</p>
<p>在其他站点，有一个类似但更灵活的日志滚动程序叫cronolog 。</p>
<p>如果有较简单的离线处理日志的方案，就不应该使用条件日志和管道日志，即使它们非常强大。</p>
<p><strong>6.虚拟主机日志</strong></p>
<p>如果服务器配有若干虚拟主机，那么还有几个控制日志文件的功能。首先，可以把日志指令放在&lt;VirtualHost&gt;段之外，让它们与主服务器使用同一个访问日志和错误日志来记录所有的请求和错误，但是这样就不能方便的获得每个虚拟主机的信息了。</p>
<p>如果把CustomLog或ErrorLog指令放在&lt;VirtualHost&gt;段内，所有对这个虚拟主机的请求和错误信息会被记录在其私有的日志文件中，那些没有在&lt;VirtualHost&gt;段内使用日志指令的虚拟主机将仍然和主服务器使用同一个日志。这种方法对虚拟主机较少的服务器很有用，但虚拟主机非常多时，就会带来管理上的困难，还经常会产生文件描述符短缺的问题。</p>
<p><strong>7.其他日志文件</strong><br />
略。。。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2009年02月11号 -- <a href="http://ourapache.com/archives/130" title="实时跟踪log变化的工具Apachetop">实时跟踪log变化的工具Apachetop</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/log" title="log" rel="tag">log</a>, <a href="http://ourapache.com/archives/tag/%e6%97%a5%e5%bf%97" title="日志" rel="tag">日志</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/184/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache并发控制、查看进程数、TCP连接、压缩功能说明</title>
		<link>http://ourapache.com/archives/181</link>
		<comments>http://ourapache.com/archives/181#comments</comments>
		<pubDate>Wed, 25 Feb 2009 15:55:36 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[压缩]]></category>
		<category><![CDATA[并发]]></category>
		<category><![CDATA[进程]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=181</guid>
		<description><![CDATA[一：apache有关并发控制
二：查看httpd进程数（即prefork模式下Apache能够处理的并发请求数）
三：查看Apache的并发请求数及其TCP连接状态
四：检查apache是否支持压缩功能]]></description>
			<content:encoded><![CDATA[<p><strong>一：apache有关并发控制</strong></p>
<p>主要是 prefork和worker二个其中一个来控制.我们可以使用httpd -l来确定当前使用的MPM是prefork.c,还是Worker.c.</p>
<blockquote><p># httpd -l<br />
Compiled in modules:<br />
core.c<br />
<a href="http://ourapache.com/archives/tag/prefork" class="st_tag internal_tag" rel="tag" title="标签 prefork 下的日志">prefork</a>.c<br />
http_core.c<br />
mod_so.c</p></blockquote>
<p>相关的配置在httpd.conf 当中可以找到</p>
<p><strong>二：查看httpd进程数</strong>（即prefork模式下Apache能够处理的并发请求数）：</p>
<blockquote><p>ps -ef | grep httpd | wc –l</p></blockquote>
<p>出现的结果,就是当前Apache能够处理的多少个并发请求，这个值Apache根据负载情况自动调.</p>
<p><strong>三：查看Apache的并发请求数及其TCP连接状态</strong></p>
<blockquote><p>netstat -n | awk ‘/^<a href="http://ourapache.com/archives/tag/tcp" class="st_tag internal_tag" rel="tag" title="标签 tcp 下的日志">tcp</a>/ {++S[$NF]} END {for(a in S) print a,S[a]}’</p></blockquote>
<p>返回结果示例：</p>
<blockquote><p>LAST_ACK 5<br />
SYN_RECV 30<br />
ESTABLISHED 1597<br />
FIN_WAIT1 51<br />
FIN_WAIT2 504<br />
TIME_WAIT 1057</p></blockquote>
<p>其中的SYN_RECV表示正在等待处理的请求数；ESTABLISHED表示正常数据传输状态；TIME_WAIT表示处理完毕，等待超时结束的请求数。</p>
<blockquote><p><a href="http://ourapache.com/archives/tag/%e7%8a%b6%e6%80%81" class="st_tag internal_tag" rel="tag" title="标签 状态 下的日志">状态</a>：描述</p>
<p>CLOSED：无连接是活动的或正在进行</p>
<p>LISTEN：服务器在等待进入呼叫</p>
<p>SYN_RECV：一个连接请求已经到达，等待确认</p>
<p>SYN_SENT：应用已经开始，打开一个连接</p>
<p>ESTABLISHED：正常数据传输状态</p>
<p>FIN_WAIT1：应用说它已经完成</p>
<p>FIN_WAIT2：另一边已同意释放</p>
<p>ITMED_WAIT：等待所有分组死掉</p>
<p>CLOSING：两边同时尝试关闭</p>
<p>TIME_WAIT：另一边已初始化一个释放</p>
<p>LAST_ACK：等待所有分组死掉</p></blockquote>
<p>可以使用Linux下的webbench来作压力测试.</p>
<p>ExtendedStatus On 因为写入额外的时间标志，设off。</p>
<p><strong>四：检查apache是否支持压缩功能:</strong></p>
<p>Http.conf 中必须加载的模块:</p>
<blockquote><p>LoadModule headers_module<br />
#modules/mod_headers.so<br />
LoadModule deflate_module<br />
#modules/mod_deflate.so</p></blockquote>
<p>添加如下代码:</p>
<blockquote><p>(</p>
<p>AddOutputFilterByType DEFLATE text/html text/plain text/css application/x-httpd-<a href="http://ourapache.com/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> application/x-javascript text/css</p>
<p>DeflateCompressionLevel 6</p>
<p>SetOutputFilter DEFLATE</p>
<p>#DeflateFilterNote Input instream</p>
<p>#DeflateFilterNote Output outstream</p>
<p>#DeflateFilterNote Ratio ratio</p>
<p>#LogFormat ‘”%r” %{outstream}n/%{instream}n (%{ratio}n%%)’ deflate</p>
<p>#CustomLog logs/deflate_<a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">log</a>.log deflate</p>
<p>)</p></blockquote>
<p>完善部分:</p>
<p> </p>
<blockquote><p>AddOutputFilterByType DEFLATE text/html text/plain text/css application/x-httpd-php application/x-javascript text/css</p>
<p>AddOutputFilter DEFLATE css #压缩css文件</p>
<p>AddOutputFilter DEFLATE js #压缩js文件</p>
<p># Don’t compress images #对照片文件不进行压缩处理</p>
<p>SetEnvIfNoCase Request_URI (?:gif|jpe?g|png)$ no-gzip dont-vary</p>
<p>SetEnvIfNoCase Request_URI (?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary</p>
<p>SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary</p>
<p>#SetEnvIfNoCase Request_URI .(css|js)$ no-gzip dont-vary</p>
<p># Make sure proxies don’t deliver the wrong content</p>
<p>Header append Vary User-Agent env=!dont-vary</p>
<p>DeflateCompressionLevel 6</p>
<p>SetOutputFilter DEFLATE</p>
<p>#DeflateFilterNote Input instream</p>
<p>#DeflateFilterNote Output outstream</p>
<p>#DeflateFilterNote Ratio ratio</p>
<p>#LogFormat ‘”%r” %{outstream}n/%{instream}n (%{ratio}n%%)’ deflate</p>
<p>#CustomLog logs/deflate_log.log deflate</p></blockquote>
<p> </p>
<p>php.ini的压缩机制配置位置:默认情况下是关闭的。</p>
<blockquote><p>#vi /etc/php.ini<br />
=================================================<br />
output_buffering = Off<br />
output_handler =<br />
zlib.output_compression = Off</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年04月8号 -- <a href="http://ourapache.com/archives/238" title="apache软件体系结构  ">apache软件体系结构  </a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/94" title="使用gzip压缩来压缩网页之apache的相关配置">使用gzip压缩来压缩网页之apache的相关配置</a></li><li>2009年02月6号 -- <a href="http://ourapache.com/archives/79" title="TCP 相关参数解释">TCP 相关参数解释</a></li><li>2009年01月6号 -- <a href="http://ourapache.com/archives/35" title="不再为Apache进程淤积、耗尽内存而困扰">不再为Apache进程淤积、耗尽内存而困扰</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/tcp" title="tcp" rel="tag">tcp</a>, <a href="http://ourapache.com/archives/tag/%e5%8e%8b%e7%bc%a9" title="压缩" rel="tag">压缩</a>, <a href="http://ourapache.com/archives/tag/%e5%b9%b6%e5%8f%91" title="并发" rel="tag">并发</a>, <a href="http://ourapache.com/archives/tag/%e8%bf%9b%e7%a8%8b" title="进程" rel="tag">进程</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/181/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网站服务器(Apache)的日志与监视</title>
		<link>http://ourapache.com/archives/176</link>
		<comments>http://ourapache.com/archives/176#comments</comments>
		<pubDate>Wed, 25 Feb 2009 10:20:53 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[日志]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=176</guid>
		<description><![CDATA[Apache提供很多检测和日志工具来追踪服务器的正确运行。默认的Apache配置提供两个日志文件，放置在安装目录下的日志目录里面。access_log这个文件（在windows下对应access.log文件）包含了服务器已经处理过的请求的信息，比如说请求的URL，客户端的IP地址，请求是否被成功完成等。error_log 这个文件（在windows下对应error.log文件）包含了与错误情况相关的信息，以及服务器生命周期中不同的大事件。]]></description>
			<content:encoded><![CDATA[<p><strong>默认的Apache日志文件</strong></p>
<p>Apache提供很多检测和日志工具来追踪服务器的正确运行。默认的Apache配置提供两个日志文件，放置在安装目录下的日志目录里面。access_log这个文件（在windows下对应access.log文件）包含了服务器已经处理过的请求的信息，比如说请求的URL，客户端的IP地址，请求是否被成功完成等。error_<a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">log</a> 这个文件（在windows下对应error.log文件）包含了与错误情况相关的信息，以及服务器生命周期中不同的大事件。</p>
<p><strong>创建日志格式</strong></p>
<blockquote><p>LogFormat “%h %l %u %t \”%r\” %&gt;s %b” common<br />
LogFormat “%h %l %u %t \”%r\” %&gt;s %b”<br />
\”%{Referer}i\” \”%{User-agent}i\”" combined</p></blockquote>
<p>LogFormat指令允许你告诉Apache你想要记录请求的哪些方面。而你仍需附加的指令来告诉Apache在哪里记录那些信息，这在下一章中将会介绍。下面的例子显示了两种最受欢迎的格式的配置：普通日志格式和整合日志格式。当Apache收到一个请求，他将会用相应的请求属性来替代以%为前缀的每一个域。如果您正在使用普通日志格式，您的日志文件里的每一项输入看起来都将是这样的：</p>
<blockquote><p>192.168.200.4 &#8211; someuser [12/Jun/2005:08:33:34<br />
+0500] “GET /example.png HTTP/1.0&#8243; 200 1234</p></blockquote>
<p>如果您正在使用整合日志格式，您的日志文件里的每一项输入看起来则都将是这样的：</p>
<blockquote><p>192.168.200.4 &#8211; someuser [12/Jun/2005:08:33:34<br />
+0500] “GET /example.png HTTP/1.0&#8243; 200 1234<br />
<a href="http://www.example.com/index.html" target="_blank"><span style="color: #0000ff;">http://www.example.com/index.html</span></a> “Mozilla/5.0<br />
(Windows; U; Windows NT 5.1; en-US; rv:1.7.7)”</p></blockquote>
<p>尽管有附件提供日志格式的详尽索引，下表描述了一些最为重要的域：</p>
<blockquote><p># %h: 客户端（例如，浏览器）向服务器发出连接请求时自己的当时的IP地址或域名(需开启HostNameLookups)。<br />
# %u: 使用HTTP方式认证用户时，记录下的用户的编号。<br />
# %t: 服务器接受到连接请求的时间。<br />
# %r: 客户端发出的原始连接请求中的文本信息，包含所使用的HTTP方法。<br />
# %&gt;s: 服务器应答浏览器后的返回状态代码，200表示请求成功。.<br />
# %b: 服务器应答浏览器发出的单个请求的回传对象的内容大小（字节为单位），不统计数据包头部字节。<br />
整合日志格式在普通日志格式的基础上扩展出了两个附加的域。定义为：<br />
# %{Referer}i: 连接请求数据包包头，包含指向当前页面的文档关联信息。<br />
# %{User-agent}i: 用户代理连接请求数据包包头，包含客户浏览器的信息。</p></blockquote>
<p><strong>创建一个自定义日志文件</strong></p>
<blockquote><p>CustomLog logs/access_log common<br />
TransferLog logs/sample.log</p></blockquote>
<p>您可能会想创建Apache自带以外的新的日志文件。下面的例子将运用CustomLog来创建一个新的日志文件，并保存由一个之前定义好的日志格式，即前一章提到的common，所定义的信息。您还可以用格式本身的定义来替换昵称。一个附加的，更为简单的指令是Transferlog，它只接受最后一个LogFormat指令提供的定义。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2009年02月11号 -- <a href="http://ourapache.com/archives/130" title="实时跟踪log变化的工具Apachetop">实时跟踪log变化的工具Apachetop</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/117" title="让Apache按日期保存日志数据">让Apache按日期保存日志数据</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/log" title="log" rel="tag">log</a>, <a href="http://ourapache.com/archives/tag/%e6%97%a5%e5%bf%97" title="日志" rel="tag">日志</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/176/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache 的mime.types文件</title>
		<link>http://ourapache.com/archives/163</link>
		<comments>http://ourapache.com/archives/163#comments</comments>
		<pubDate>Wed, 25 Feb 2009 10:07:18 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[mime.types]]></category>
		<category><![CDATA[wap]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=163</guid>
		<description><![CDATA[Wap中常用的MIME Type]]></description>
			<content:encoded><![CDATA[<p>Apache 是一个优秀的应用服务器程序，已经提供了对一般WAP的支持。</p>
<p>如果你不确定你的Apache是否配置好了WAP支持，可以看一下Apache的配置文件”<a href="http://ourapache.com/archives/tag/mimetypes" class="st_tag internal_tag" rel="tag" title="标签 mime.types 下的日志">mime.types</a>”。如果配置文件中这么一行：</p>
<p>text/vnd.<a href="http://ourapache.com/archives/tag/wap" class="st_tag internal_tag" rel="tag" title="标签 wap 下的日志">wap</a>.wml                                      wml</p>
<p>如果没有的话，也不用着急，加上这一行就行了。如果你要配置全面一些的话还要加上以下几行：</p>
<p>image/vnd.wap.wbmp                               wbmp</p>
<p>text/vnd.wap.wmls                                  wmls</p>
<p>application/vnd.wap.wmlc                         wmlc</p>
<p>application/vnd.wap.wmlscriptc                wmlsc</p>
<p>text/vnd.wap.wmlscript                            wsc</p>
<p>text/vnd.wap.wmlscript                            wmlscript</p>
<p>修改好以后，重新启动Apache就可以了。</p>
<p>如果要系统支持index.wml的话，还得配置Apache的httpd.conf，类似添加index.php的配置了，略。</p>
<p>只所以说支持的是一般WAP，像一些安装文件jar，jad，sis之类的安装文件就没有默认支持。</p>
<p>如果要使Apache支持OTA（WAP PUSH）下载的话，还得在mime.types中添加下面几行：</p>
<p>AddType image/vnd.nokia.ota-bitmap ota</p>
<p>AddType text/vnd.sun.j2me.app-descriptor jad</p>
<p>AddType application/java-archive jar</p>
<p>AddType application/vnd.Nokie.ringing-tone rng</p>
<p>AddType application/vnd.symbian.install sis</p>
<p>（不加的话，下载类似sis的安装文件会直接打开该文件，而不会直接执行。）</p>
<p>更详细的文件类型配置如下：</p>
<p>AddType text/vnd.sun.j2me.app-descriptor jad</p>
<p>AddType application/java-archive jar</p>
<p>AddType text/vnd.wap.wml wml</p>
<p>AddType audio/amr amr</p>
<p>AddType audio/midi mid</p>
<p>AddType audio/midi midi</p>
<p>AddType application/vnd.Nokie.ringing-tone rng</p>
<p>AddType application/vnd.symbian.install sis</p>
<p>AddType application/vnd.wap.wmlc wmlc</p>
<p>AddType text/vnd.wap.wmlscript wmls</p>
<p>AddType text/vnd.wap.wmlscript wmlsc</p>
<p>AddType application/vnd.wap.sic sic</p>
<p>AddType text/vnd.wap.si si</p>
<p>AddType text/vnd.wap.sl sl</p>
<p>AddType application/vnd.wap.slc slc</p>
<p>AddType text/x-vCalendar vcs</p>
<p>AddType text/v-vCard vcf</p>
<p>AddType application/vnd.nokia.gamedata nqd</p>
<p>AddType application/x-nokiagamedata ngd</p>
<p>AddType image/vnd.wap.wmbp wbmp</p>
<p>AddType image/x-bmp bmp</p>
<p>AddType image/x-epoc-mbm mbm</p>
<p>AddType image/vnd.nok-3dscreensaver n3a</p>
<p>AddType text/x-co-desc cod</p>
<p>AddType image/vnd.nok-oplogo-colornokia-op-logo nok</p>
<p>AddType application/x-pmd .pmd</p>
<p>AddType audio/vnd.qcelp .qcp</p>
<p>AddType application/x-smaf .mmf</p>
<p>AddType application/vnd.smaf</p>
<p>保存后，重启下Apache，OK了！</p>
<h3  class="related_post_title">无相关文章，以下随机显示</h3><ul class="related_post"><li>2009年01月22号 -- <a href="http://ourapache.com/archives/68" title="apache最大连接数性能测试">apache最大连接数性能测试</a></li><li>2009年02月7号 -- <a href="http://ourapache.com/archives/97" title="使用apache下的301设置来做域名的更换转移">使用apache下的301设置来做域名的更换转移</a></li><li>2009年06月15号 -- <a href="http://ourapache.com/archives/259" title="16个简单实用的.htaccess小贴示">16个简单实用的.htaccess小贴示</a></li><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年08月12号 -- <a href="http://ourapache.com/archives/268" title="Etag和Expires">Etag和Expires</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年02月17号 -- <a href="http://ourapache.com/archives/142" title="在64位机器上关于Apache 2.2.3版的编译问题">在64位机器上关于Apache 2.2.3版的编译问题</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/170" title="Apache 两种虚拟主机方式的区别">Apache 两种虚拟主机方式的区别</a></li><li>2009年08月16号 -- <a href="http://ourapache.com/archives/292" title="Apache两种运行方式比较:Standalone和inetd">Apache两种运行方式比较:Standalone和inetd</a></li><li>2009年06月7号 -- <a href="http://ourapache.com/archives/251" title="apxs是Apache编译和安装扩展模块的工具">apxs是Apache编译和安装扩展模块的工具</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/mimetypes" title="mime.types" rel="tag">mime.types</a>, <a href="http://ourapache.com/archives/tag/wap" title="wap" rel="tag">wap</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/163/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache高级配置中文详解</title>
		<link>http://ourapache.com/archives/123</link>
		<comments>http://ourapache.com/archives/123#comments</comments>
		<pubDate>Tue, 10 Feb 2009 07:20:31 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=123</guid>
		<description><![CDATA[Apache安装成功后，在conf子目录下有四个文件：httpd.conf、srm.conf、access.conf、magic（请注意：在 www-howto文档中，说第四个文件是mime.types，但在实际安装中，在conf子目录下是magic文件）。httpd.conf是 Apache设置文件中的主文件，httpd程序启动时会先读取httpd.conf。srm.conf是数据配置文件，在这个文件中主要设置WWW Server读取文件的目录、目录索引时的画面、CGI执行时的目录等等。access.conf是负责基本的读取文件控制，限制目录所能执行的功能及访问目录的权限设置。]]></description>
			<content:encoded><![CDATA[<p>目前WWW Server软件有许多，能运行在Linux下的也不少，有NCSA HTTPd Server、CERN HTTPd Server、pache、Netscape Fast Track Server、Zeus Server等。这些软件各有特色：NCSA（美国伊利诺斯大学的国家超级计算应用中心）是WWW Browser Mosaic发迹之地，也是Netscape公司的安德森成名的地方；CERN（欧洲原子核研究中心）是WWW的起源地，1989年蒂姆•贝纳斯-李正是在这开发成功了世界上第一个Web服务器和客户机。这两家推出的WWW Server功能齐全，成为同类软件的标准，再加上它们都是Freeware，因此刚一推出就大受欢迎。前几年，在linux下WWW Server软件使用最多的是NCSA和CERN，但这一两年来，后起之秀Apache却独领风骚，号称”WWW Server之王”。在最新的Red Hat、Slackware和 OpenLinux各版本中都包含了Apache。<br />
　　<br />
　　Apache是在NCSA的基础上发展起来的，因此这二者的配置文件十分相似。<br />
　　<br />
　　一、安装<br />
　　Apache的安装十分简单。最好在安装RedHat时，选择安装Web Server，这样即使你对编译操作不熟的话，也能轻轻松松把服务器架设起来。<br />
　　<br />
　　如果你想亲自编译源文件，那么你已经不是一个初学者，建议你直接去看How-To文档或其他资料。打开机器，进入X-Window系统后，启动 Netscape Navigator，敲入本机的IP地址，如果出现”It worked”的欢迎页面，那说明服务器程序工作正常。你可以进行下一步配置工作。在不同的版本下，服务器默认的工作根目录也不一样。Red Hat默认的是/etc/httpd，配置文件在/etc/httpd/conf目录下，页面文件在/home/httpd目录下。<br />
　　<br />
　　二、 设置httpd.conf、srm.conf、access.conf文件<br />
　　Apache安装成功后，在conf子目录下有四个文件：httpd.conf、srm.conf、access.conf、magic（请注意：在 www-howto文档中，说第四个文件是mime.types，但在实际安装中，在conf子目录下是magic文件）。httpd.conf是 Apache设置文件中的主文件，httpd程序启动时会先读取httpd.conf。srm.conf是数据配置文件，在这个文件中主要设置WWW Server读取文件的目录、目录索引时的画面、CGI执行时的目录等等。access.conf是负责基本的读取文件控制，限制目录所能执行的功能及访问目录的权限设置。<br />
　　<br />
　　下面将简单对这三个数据设置文件进行说明。<br />
　　<br />
　　httpd.conf文件<br />
　　<br />
　　TransferLog：<br />
　　<br />
　　如果你想知道你的网站上哪个页面最受来访者的欢迎，在一段时间内有多少人访问你的站点，你当然可以设置一个计数器，但每页都设计数器，太繁琐而且得到的结果不太煽俊Ｗ詈玫陌旆ㄇ查看相觢og文件，TransferLog命令就是指定当浏览器要求服务器传送文件时记录到所设置的文件，可以根据此文件查看有哪些用户看过哪些HTML文件。可用一些程序分析这个文件的数据，得出监测各种有用的数据。默认的访问log文件是logs/access_<a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">log</a>。<br />
　　<br />
　　ErrorLog：<br />
　　<br />
　　这个命令是指定当WWW Server运转过程中发生问题时错误信息存放到哪个文件。默认是logs/error_log。<br />
　　<br />
　　VirtualHost：<br />
　　<br />
　　这个命令是用来设置虚拟主机，即用一台主机执行多个域名的WWW Server。详细命令使用将在第三部分详细解释。<br />
　　<br />
　　srm.conf<br />
　　<br />
　　DocumentRoot：<br />
　　<br />
　　指定WWW Server存放html文件的根目录。WWW Server从硬盘中读取html文件传送给浏览器，并不是可从任一个目录中读取文件，而是从一个特定目录中开始读取文件，这个特定的目录就是由 DocumentRoot命令来指定。red hat5.2中默认的目录是/home/httpd/html。<br />
　　<br />
　　如果用户访问http://www.swm.com.cn/netlife/index.html，此时WWW Server并不是从系统的根目录下的netlife目录中读取index.html，而是从/home/httpd/html/netlife目录中读取index.html文件。<br />
　　UserDir：<br />
　　<br />
　　如果要在WWW Server上给一些用户开设空间，搁放个人主页，最好不要把每个人的html文件都放到DocumentRoot目录中，用UserDir命令可让每个人的页面放置在自己的home目录中。默认的目录是public_html。<br />
　　<br />
　　如果UserDir设置的目录是public_html，而Username是yan，而该user的home目录是/home/yan，那你访问http://www.swm.com.cn/~yan/intr.html时所看到的intr.html文件存放在/home/yan/public_html中，而不是/home/httpd/html。<br />
　　<br />
　　access.conf<br />
　　<br />
　　如果你有些目录只想让某些人访问，或者只允许在特定的目录下允许CGI程序，这时就要对access.conf进行修改。<br />
　　<br />
　　Apache的存取控制方式有两种：一是”整体存取控制”，只通过access.conf来控制文件的设置，来限定目录所能执行的功能及存取目录的权限设置。二是”特定目录存取控制”，在特定目录中建立存取设置文件，这个文件名在srm.conf中的AcessFileName来决定，默认是.<a href="http://ourapache.com/archives/tag/htaccess" class="st_tag internal_tag" rel="tag" title="标签 htaccess 下的日志">htaccess</a>。例如某些目录中的文件只允许某些人访问，那可在该目录下建立.htaccess文件，当WWW Server读取该目录时便会自动读取.htaccess来决定是否读取执行或要求口令验证。这两种方式所使用的命令几乎相同，而且设置的格式也相同。<br />
　　<br />
　　Directory：<br />
　　<br />
　　说明要设置的目录，然后再用命令来设置目录的功能和权限。<br />
　　<br />
　　Options：<br />
　　<br />
　　设置目录可以执行哪些功能。有None、All、ExecCGI、Includes、Indexs、IncludesNoExec、 FollowSymlink、SymlinksOwnerMatch等选项。如果想让某个目录可以执行CGI程序，那么应在Options命令中加上 ExecCGI选项。<br />
　　<br />
　　Require：<br />
　　<br />
　　设置可以对所指定目录以指定方式来存取的Users和Group。该命令执行后，当读取该目录数据时，系统会要求输入Username和Password。<br />
　　<br />
　　忠告：修改完设置文件后，不要像在Windows工作那样，重启机器使其生效。要记住，你现在linux下，使用linux的好处之一就是不用再见到 Windows 98那死机时的蓝屏以及不必对配置文件做了一点点修改就无聊而又频繁地重启机器。你的WWW服务器任何时候都有很多人在访问，频繁地重启机器将把你的客人赶跑。要学会不重启机器，而是重新启动一个正执行的程序（Process，严格一点应叫做进程、作业）。可以用kill命令来使程序重新启动。具体 kill的使用参见有关文档。<br />
　　<br />
　　先用ps命令查看httpd的pid号，然后用kill命令杀死它，重新启动httpd。具体命令如下：<br />
　　<br />
　　linux&gt; ps -x<br />
　　linux&gt; kill -HUP 13668<br />
　　<br />
　　（13668是假设httpd的pid号，在实际使用中，不同的情况值也不同）<br />
　　<br />
　　这样就可将httpd重新启动，使修改的配置文件生效。看完上面一大堆命令，是不是有些烦，其实你不了解这些命令也无所谓，用系统默认设置也能正常工作。<br />
　　<br />
　　三、 虚拟主机（Virtual Host）的设置<br />
　　作为系统管理员，若你只有一个IP地址，却有好几个域名，又要求访问每个域名都要看到不同的内容，那怎么办？总不至于为每个域名都配上一台服务器吧。这就要采用虚拟主机（Virtual Host）技术，幸好Apache就支持这种功能。虚拟主机有两种方式：IP－Based（基于IP式）、Name-based（基于域名式）。 IP－Based指的是一个域名对应一个IP地址，而Name-based指的是多个域名对应一个IP地址。<br />
　　<br />
　　虚拟主机的设置并不复杂，只要在httpd.conf文件中加入相应的命令就行。<br />
　　<br />
　　下面是一个Name-based（基于域名式）虚拟主机的httpd.conf例子（编者注：因篇幅原因，我们这只给出了相关部分，全文见www.swm.com.cn）。IP为：192.168.188.20，两个域名分别是long.com.cn、short.com.cn。<br />
　　<br />
　　httpd.conf:<br />
　　<br />
　　NameVirtualHost 192.168.188.20<br />
　　<br />
　　ServerAdminwebmaster@long.com<br />
　　ServerNamewww.long.com<br />
　　DocumentRoot /home/httpd/long/html<br />
　　<br />
　　ErrorLog logs/error_log<br />
　　TransferLog logs/access_log<br />
　　<br />
　　ServerAdminwebmaster@short.com<br />
　　ServerNamewww.short.com<br />
　　DocumentRoot /home/httpd/short/html<br />
　　ErrorLog logs/short.com-error_log<br />
　　TransferLog logs/short.com-access_log<br />
　　<br />
　　NameVirtualHost命令指定在哪个IP上设置虚拟主机<br />
　　<br />
　　在VirtualHost命令中进行各个主机的具体设置。<br />
　　<br />
　　ServerAdmin命令是设定当WWW Server执行有问题时，会将ServerAdmin所设置的E-mail传送到浏览器，让使用者用该E-mail与系统管理员联系。<br />
　　<br />
　　ServerName命令是设置WWW Server的域名。<br />
　　<br />
　　四、 提供个人主页空间、用户homepage的设定<br />
　　经常见到某些网站提供个人主页，显得很神气，其实你也可以开放你机器上的空间给别人，这很简单就能实现。只要你按照下面的提示对你的WWW服务器配置文件进行修改。<br />
　　<br />
　　给用户开放个人主页空间，一是要确定用户主页的存放目录，二是开放用户主页目录的读取权限。<br />
　　<br />
　　方法一<br />
　　<br />
　　你以root的身份给用户chen开个帐号，系统自动会给chen分配一空间/home/user，而后在/home/chen的目录下建一public_html的子目录，子目录的属性要设成other可读和可执行的。<br />
　　<br />
　　接着修改access.conf。在文件的最后加上以下一段：<br />
　　<br />
　　AllowOverride None<br />
　　order allow,deny<br />
　　allow from all<br />
　　<br />
　　而后，重新运行httpd，用户就可以通过http://www.swm.com.cn/~chen/访问chen的个人主页。<br />
　　这种方法的优点是方便，缺点是安全性太差。<br />
　　<br />
　　方法二<br />
　　<br />
　　另一种办法是在/home/httpd目录下为用户chen建个目录chen。修改srm.conf中的UserDir为/home/httpd/*/html，接着重新运行httpd便可以了。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2010年03月9号 -- <a href="http://ourapache.com/archives/318" title="Apache2中俩种设置PHP的异同">Apache2中俩种设置PHP的异同</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li><li>2008年12月25号 -- <a href="http://ourapache.com/archives/1" title="使用gzip将你的Apache速度提高十倍">使用gzip将你的Apache速度提高十倍</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/123/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>让Apache按日期保存日志数据</title>
		<link>http://ourapache.com/archives/117</link>
		<comments>http://ourapache.com/archives/117#comments</comments>
		<pubDate>Tue, 10 Feb 2009 07:01:27 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache基础知识]]></category>
		<category><![CDATA[日志]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=117</guid>
		<description><![CDATA[今天是2007年3月27日，那今天的日志文件存储名为20070327.log,明天的存储名就是20070328.log，这样循环下去。]]></description>
			<content:encoded><![CDATA[<p>今天是2007年3月27日，那今天的日志文件存储名为20070327.<a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">log</a>,明天的存储名就是20070328.<a href="http://ourapache.com/archives/tag/log" class="st_tag internal_tag" rel="tag" title="标签 log 下的日志">log</a>，这样循环下去。</p>
<p>方法如下：</p>
<p>Luinx<br />
CustomLog “|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/%Y_%m_%d.access.log 86400 480″ common<br />
其中/usr/local/是你安装apache的路径,这样每一天生成一个日志文件</p>
<p>windows<br />
CustomLog “|bin/rotatelogs.exe -l youapachelogdir/access%Y%m%d.log 86400″ common</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年06月1号 -- <a href="http://ourapache.com/archives/243" title="玩转apache之日志">玩转apache之日志</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/227" title="通过SNMP协议来监视Apache服务器">通过SNMP协议来监视Apache服务器</a></li><li>2009年03月9号 -- <a href="http://ourapache.com/archives/224" title="监视并记录Apache网站服务器的运行">监视并记录Apache网站服务器的运行</a></li><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/176" title="网站服务器(Apache)的日志与监视">网站服务器(Apache)的日志与监视</a></li><li>2009年02月25号 -- <a href="http://ourapache.com/archives/172" title="查询并禁止apache中异常访问量的用户">查询并禁止apache中异常访问量的用户</a></li></ul>
	标签：<a href="http://ourapache.com/archives/category/basic" title="Apache基础知识" rel="tag">Apache基础知识</a>, <a href="http://ourapache.com/archives/tag/%e6%97%a5%e5%bf%97" title="日志" rel="tag">日志</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/117/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

