<?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>Terrysco&#039;s Blog &#187; apache</title>
	<atom:link href="http://www.terrysco.com/node/tag/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://www.terrysco.com</link>
	<description>仅关注于互联网行业， Linux平台开发。</description>
	<lastBuildDate>Sat, 05 Nov 2011 21:24:06 +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>Apache Rewrite</title>
		<link>http://www.terrysco.com/node/apache-rewrite.html</link>
		<comments>http://www.terrysco.com/node/apache-rewrite.html#comments</comments>
		<pubDate>Wed, 23 Jun 2010 03:59:57 +0000</pubDate>
		<dc:creator>terrysco</dc:creator>
				<category><![CDATA[Linux/Mac/DB]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.terrysco.com/?p=354</guid>
		<description><![CDATA[Apache的rewrite的重写非常常用,现总结了一下. Apache mod_rewrite规则重写的标志一览 R[=code](force redirect) 强制外部重定向 强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定，将用缺省的302 HTTP状态码。 F(force URL to be forbidden)禁用URL,返回403HTTP状态码。 G(force URL to be gone) 强制URL为GONE，返回410HTTP状态码。 P(force proxy) 强制使用代理转发。 L(last rule) 表明当前规则是最后一条规则，停止分析以后规则的重写。 N(next round) 重新从第一条规则开始运行重写过程。 C(chained with next rule) 与下一条规则关联 如果规则匹配则正常处理，该标志无效，如果不匹配，那么下面所有关联的规则都跳过。 T=MIME-type(force MIME type) 强制MIME类型 NS (used only if no internal sub-request) 只用于不是内部子请求 NC(no case) 不区分大小写 QSA(query string append) 追加请求字符串 NE(no URI [...]]]></description>
			<content:encoded><![CDATA[<p>Apache的rewrite的重写非常常用,现总结了一下.</p>
<p><strong>Apache mod_rewrite规则重写的标志一览</strong></p>
<p><strong>R</strong>[=code](force redirect) 强制外部重定向<br />
强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定，将用缺省的302 HTTP状态码。<br />
<strong>F</strong>(force URL to be forbidden)禁用URL,返回403HTTP状态码。<br />
<strong>G</strong>(force URL to be gone) 强制URL为GONE，返回410HTTP状态码。<br />
<strong>P</strong>(force proxy) 强制使用代理转发。<br />
<strong>L</strong>(last rule) 表明当前规则是最后一条规则，停止分析以后规则的重写。<br />
<strong>N</strong>(next round) 重新从第一条规则开始运行重写过程。<br />
<strong>C</strong>(chained with next rule) 与下一条规则关联<br />
如果规则匹配则正常处理，该标志无效，如果不匹配，那么下面所有关联的规则都跳过。<br />
<strong>T</strong>=MIME-type(force MIME type) 强制MIME类型<br />
<strong>NS</strong> (used only if no internal sub-request) 只用于不是内部子请求<br />
<strong>NC</strong>(no case) 不区分大小写<br />
<strong>QSA</strong>(query string append) 追加请求字符串<br />
<strong>NE</strong>(no URI escaping of output) 不在输出转义特殊字符<br />
例如：RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] 将能正确的将/foo/zoo转换成/bar?arg=P1=zed<br />
<strong>PT</strong>(pass through to next handler) 传递给下一个处理<br />
例如：<br />
RewriteRule ^/abc(.*) /def$1 [PT] # 将会交给/def规则处理<br />
Alias /def /ghi<br />
<strong>S</strong>=num(skip next rule(s)) 跳过num条规则<br />
<strong>E</strong>=VAR:VAL(set environment variable) 设置环境变量</p>
<p><strong>使用mod_rewrite时常用的服务器变量：</strong><br />
HTTP headers:HTTP_USER_AGENT, HTTP_REFERER, HTTP_COOKIE, HTTP_HOST, HTTP_ACCEPT<br />
connection &amp; request: REMOTE_ADDR, QUERY_STRING<br />
server internals: DOCUMENT_ROOT, SERVER_PORT, SERVER_PROTOCOL<br />
system stuff: TIME_YEAR, TIME_MON, TIME_DAY</p>
<p><strong>RewriteRule规则表达式的说明：</strong><br />
. 匹配任何单字符<br />
[chars] 匹配字符串:chars<br />
[^chars] 不匹配字符串:chars<br />
text1|text2 可选择的字符串:text1或text2<br />
? 匹配0到1个字符<br />
* 匹配0到多个字符<br />
+ 匹配1到多个字符<br />
^ 字符串开始标志<br />
$ 字符串结束标志<br />
\n 转义符标志</p>
<p>反向引用 $N 用于 RewriteRule 中匹配的变量调用(0 &lt;= N &lt;= 9)<br />
反向引用 %N 用于 RewriteCond 中最后一个匹配的变量调用(1 &lt;= N &lt;= 9)</p>
<p><strong>RewriteCond适用的标志符</strong><br />
‘nocase|NC’ (no case)忽略大小<br />
‘ornext|OR’ (or next condition)逻辑或，可以同时匹配多个RewriteCond条件</p>
<p><strong>RewriteRule适用的标志符</strong><br />
‘redirect|R [=code]’ (force redirect)强迫重写为基于http开头的外部转向(注意URL的变化) 如：[R=301,L]<br />
‘forbidden|F’ (force URL to be forbidden)重写为禁止访问<br />
‘proxy|P’ (force proxy)重写为通过代理访问的http路径<br />
‘last|L’ (last rule)最后的重写规则标志，如果匹配，不再执行以后的规则<br />
‘next|N’ (next round)循环同一个规则，直到不能满足匹配<br />
‘chain|C’ (chained with next rule)如果匹配该规则，则继续下面的有Chain标志的规则。<br />
‘type|T=MIME-type’ (force MIME type)指定MIME类型<br />
‘nosubreq|NS’ (used only if no internal sub-request)如果是内部子请求则跳过<br />
‘nocase|NC’ (no case)忽略大小<br />
‘qsappend|QSA’ (query string append)附加查询字符串<br />
‘noescape|NE’ (no URI escaping of output)禁止URL中的字符自动转义成%[0-9]+的形式。<br />
‘passthrough|PT’ (pass through to next handler)将重写结果运用于mod_alias<br />
’skip|S=num’ (skip next rule(s))跳过下面几个规则<br />
‘env|E=VAR:VAL’ (set environment variable)添加环境变量</p>
<p><strong>实战</strong><br />
例子：<br />
RewriteEngine on<br />
RewriteCond %{HTTP_USER_AGENT} ^MSIE [NC,OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Opera [NC]<br />
RewriteRule ^.* &#8211; [F,L] 这里”-”表示没有替换，浏览器为IE和Opera的访客将被禁止访问。</p>
<p>例子：<br />
RewriteEngine On<br />
RewriteBase /test<br />
RewriteCond %{REQUEST_FILENAME}.php -f<br />
RewriteRule ([^/]+)$ /test/$1.php<br />
#for example: /test/admin =&gt; /test/admin.php<br />
RewriteRule ([^/]+)\.html$ /test/$1.php [L]<br />
#for example: /test/admin.html =&gt; /test/admin.php</p>
<p>限制目录只能显示图片<br />
&lt; IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|swf)$<br />
RewriteRule .*$ &#8211; [F,L]<br />
&lt; /IfModule&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.terrysco.com/node/apache-rewrite.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache的userdir配置403forbidden问题</title>
		<link>http://www.terrysco.com/node/apache-userdir-forbidden.html</link>
		<comments>http://www.terrysco.com/node/apache-userdir-forbidden.html#comments</comments>
		<pubDate>Mon, 02 Mar 2009 01:36:29 +0000</pubDate>
		<dc:creator>terrysco</dc:creator>
				<category><![CDATA[Linux/Mac/DB]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.anyliv.com/www.terrysco.com/?p=81</guid>
		<description><![CDATA[<p>想在自己机器上搭建个web环境测试方便，谁知道UserDir指令怎么都配置不好，浏览器都会显示403forbidden。这个问题郁闷了好久，大部分文档都说public_html目录要把权限设置为755,而我的权限本来就是755啊。还有说UserDir指令要设置disabled和enabled，我想那只是对特别用户的权限设置，我根本不用理会这个，但依然问题如故。今天看到这些注释：</p><p><b># UserDir: The name of the directory that is appended onto a user's home<br />...</b></p><p>&#160;</p>
]]></description>
			<content:encoded><![CDATA[<p>想在自己机器上搭建个web环境测试方便，谁知道UserDir指令怎么都配置不好，浏览器都会显示403forbidden。这个问题郁闷了好久，大部分文档都说public_html目录要把权限设置为755,而我的权限本来就是755啊。还有说UserDir指令要设置disabled和enabled，我想那只是对特别用户的权限设置，我根本不用理会这个，但依然问题如故。今天看到这些注释：</p>
<p><b># UserDir: The name of the directory that is appended onto a user&#8217;s home<br /># directory if a ~user request is received.<br />#<br /># The path to the end user account &#8216;public_html&#8217; directory must be<br /># accessible to the webserver userid.  This usually means that ~userid<br /># must have permissions of 711, ~userid/public_html must have permissions<br /># of 755, and documents contained therein must be world-readable.<br /># Otherwise, the client will only receive a &quot;403 Forbidden&quot; message.</b></p>
<p>随即再看了看配置文件，将/home/terrysco目录权限设置为711,重启apache后访问http://localhost/~terrysco，成功了！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.terrysco.com/node/apache-userdir-forbidden.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apache一些设置总结</title>
		<link>http://www.terrysco.com/node/apache-summary.html</link>
		<comments>http://www.terrysco.com/node/apache-summary.html#comments</comments>
		<pubDate>Mon, 10 Nov 2008 00:30:00 +0000</pubDate>
		<dc:creator>terrysco</dc:creator>
				<category><![CDATA[Linux/Mac/DB]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.anyliv.com/www.terrysco.com/?p=55</guid>
		<description><![CDATA[<p>1. UserDir 命令，用来指定个人主页的位置。如果你有一个用户test，那么它主目录是&#34;/home/test&#34;，当客户端输入&#34;http: //yourdomain/~test&#34;，系统就会到对应的目录&#34;/home/test/UserDir/&#34;中去寻找。其中&#34;UserDir&#34;就是在UserDir命令中设置的指定目录。命令格式: UserDir [Path]例： UserDir public_html</p><p>注，这个设置对公司内部多人协同开发比较方便，结合cvs等版本管理工具，每个人在自己的开发目录进行相应模块的开发最后提交到cvs服务器，互不影响。</p>...
]]></description>
			<content:encoded><![CDATA[<p>1. UserDir 命令，用来指定个人主页的位置。如果你有一个用户test，那么它主目录是&quot;/home/test&quot;，当客户端输入&quot;http: //yourdomain/~test&quot;，系统就会到对应的目录&quot;/home/test/UserDir/&quot;中去寻找。其中&quot;UserDir&quot;就是在UserDir命令中设置的指定目录。命令格式: UserDir [Path]例： UserDir public_html</p>
<p>注，这个设置对公司内部多人协同开发比较方便，结合cvs等版本管理工具，每个人在自己的开发目录进行相应模块的开发最后提交到cvs服务器，互不影响。</p>
<p>2. 用Apache实现虚拟主机服务 （此处为转载，来源于网络）</p>
<p>　　什么是虚拟主机服务</p>
<p>　　所谓的虚拟主机服务就是指将一台机器虚拟成多台WEB服务器。举个例子来说，一家公司想从事提供主机代管服务，它为其它企业提供WEB服务。那么它肯定不是为每一家企业都各准备一台物理上的服务器，而是用一台功能较强大的大型服务器，然后用虚拟主机的形式，提供多个企业WEB服务，虽然所有的WEB服务就是这台服务器提供的，但是让访问者看起来却是在不同的服务器上获得WEB服务一样。具体地说，就是，我们可以利用虚拟主机服务将两个不同www.company1.comwww.company2.com的主页内容都存放在同一台主机上。而访问者只需输入公司的域名就可以访问想得到的主页内容。 用Apache设置虚拟主机服务通常可以采用两种方案：基于IP地址的虚拟主机和基于名字的虚拟主机，下面我们分别介绍一下它们的实现方法。以便大家在具体的应用中能够选择最合适的实现方法。</p>
<p>设置实现基于IP地址的虚拟主机服务实现前提：<br />这种方式需要在机器上设置IP别名，也就是在一台机器的网卡上绑定多个IP地址去为多个虚拟主机服务。而且要使用这项功能还要确定在你的LINUX内核中必须支持IP别名的设置，否则你还必须重新编译内核。</p>
<p>　　下面举一个拥有两个虚拟主机的服务设置，以供参考。假设，我们用来实现虚拟主机服务的机器，首先已经为自己提供了WEB服务，现<br />在将为新的一家www.company1.com提供虚拟主机服务。规划IP地址：为虚拟主机申请新的IP地址。（假设本机IP地址为202.101.2.1）</p>
<p>www.company1.com 202.101.2.2</p>
<p>2) 让ISP作好相应的域名解析工作。</p>
<p>3) 为网卡设置IP别名：</p>
<p>/sbin/ifconfig eth0:0 202.101.2.2 netmask 255.255.255.0</p>
<p>4) 重新设置&quot;/etc/httpd/conf/httpd.conf&quot;,在文件中加入：</p>
<p>&lt;VirtualHost 202.101.2.2&gt;</p>
<p>ServerAdmin webmaster@yourdomain.com</p>
<p>DocumentRoot /home/httpd/www.company1.com</p>
<p>ServerName www.company1.com</p>
<p>ErrorLog /var/log/httpd/www.company1.com/error.log</p>
<p>&lt;/VirtualHost&gt;</p>
<p>5）建立相应的目录。</p>
<p>mkdir /home/httpd/www.company1.com</p>
<p>mkdir /var/log/httpd/www.company1.com/error.log</p>
<p>6)将相应的主页内容存放在相应的目录中即可。<br />不利因素</p>
<p>这种虚拟主机的实现方法有一个严重的不足，那就是，每增加一个虚拟主机，就必须增加一个IP地址。而由于IP地址空间已经十分紧张，所以通常情况下是无法取得这么多的IP地址的。而且从某种意义上说，这也是一种IP地址浪费。设置实现基于名字的虚拟主机服务而基于名字的虚拟主机服务，是比较适合使用的一种方案。因为它不需要更多的IP地址，而且配置简单，无须什么特殊的软硬件支持。现代的浏览器大都支持这种虚拟主机的实现方法。当然，这也就是指一些早期的客户端浏览器也许不支持这种虚拟主机的实现方法。</p>
<p>　　正是以上原因，我们没有理由不使用基于名字的虚拟主机服务而使用基于IP地址的虚拟主机服务。配置基于名字的虚拟主机服务需要修改配置文<br />件/etc/httpd/conf/httpd.conf&quot;，在这个配置文件中增加以下内容。</p>
<p>NameVirtualHost 202.101.2.1</p>
<p>&lt;VirtualHost 202.101.2.1&gt;</p>
<p>ServerAdmin webmaster@yourdomain.com</p>
<p>DocumentRoot /home/httpd/www.company1.com</p>
<p>ServerName www.company1.com</p>
<p>ErrorLog /var/log/httpd/www.company1.com/error.log</p>
<p>&lt;/VirtualHost&gt;</p>
<p>&lt;VirtualHost 202.101.2.1&gt;</p>
<p>ServerAdmin webmaster@yourdomain.com</p>
<p>DocumentRoot /home/httpd/www.company2.com</p>
<p>ServerName www.company2.com</p>
<p>ErrorLog /var/log/httpd/www.company2.com/error.log</p>
<p>&lt;/VirtualHost&gt;</p>
<p>　　也就是在基于IP地址的配置基础上增加一句：NameVirtualHost 202.101.2.1而已。在本例中，为了体现只需要增加一次，所以特别地设置了两<br />个虚拟主机服务。</p>
<p>最后也是建立相应的目录，将主页内容放到相应的目录中去就可以了。</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.terrysco.com/node/apache-summary.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

