<?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>Erning.write() &#187; apache</title>
	<atom:link href="http://erning.net/tags/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://erning.net</link>
	<description>Reloading</description>
	<lastBuildDate>Fri, 18 Jun 2010 18:05:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>用mod_rewrite与mod_userdir配置apache虚拟主机</title>
		<link>http://erning.net/archives/linux-apache-vhost</link>
		<comments>http://erning.net/archives/linux-apache-vhost#comments</comments>
		<pubDate>Tue, 04 Jan 2005 15:13:06 +0000</pubDate>
		<dc:creator>erning</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[vhost]]></category>

		<guid isPermaLink="false">http://www.erning.net/archives/2005/01/04/%e7%94%a8mod_rewrite%e4%b8%8emod_userdir%e9%85%8d%e7%bd%aeapache%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba/</guid>
		<description><![CDATA[mod_userdir可以让linux机器上的用户都有一个虚拟主机，缺省目录为~/public_html。配合suexec，其还可以使各个虚拟主机的cgi程序以各自的用户身份执行。 但是mod_userdir的形式为http://servername/~username/，而我们希望可以通过不同的域名访问不同的虚拟主机。 因此我试着使用mod_rewrite将http://domainname/的访问转换为userdir的形式。apache的配置脚本httpd.conf相关内容如下(假设用户目录为/home/username) LogFormat "%{VHOST}e %V %h %l %u %t %r %>s %b %{Referer}i %{User-Agent}i" vhost CustomLog logs/vhosts_access_log vhost RewriteEngine on #RewriteLog /usr/local/apache2/logs/rewrite_log #RewriteLogLevel 9 RewriteMap lowercase int:tolower RewriteMap vhost txt:/home/vhost.map RewriteCond %{ENV:VHOST} ^$ RewriteCond %{REQUEST_URI} ^/~([^/]+) RewriteCond ${lowercase:%1} ^(.+)$ RewriteRule ^.*$ $0 [PT,E=VHOST:%1] RewriteCond %{ENV:VHOST} ^$ RewriteCond %{HTTP_HOST} !^$ RewriteCond ${lowercase:%{HTTP_HOST}} ^(.+)$ RewriteCond ${vhost:%1} [...]]]></description>
			<content:encoded><![CDATA[<p>mod_userdir可以让linux机器上的用户都有一个虚拟主机，缺省目录为~/public_html。配合suexec，其还可以使各个虚拟主机的cgi程序以各自的用户身份执行。</p>
<p>但是mod_userdir的形式为http://servername/~username/，而我们希望可以通过不同的域名访问不同的虚拟主机。</p>
<p>因此我试着使用mod_rewrite将http://domainname/的访问转换为userdir的形式。apache的配置脚本httpd.conf相关内容如下(假设用户目录为/home/username)</p>
<pre class="brush: plain">
LogFormat "%{VHOST}e %V %h %l %u %t %r %>s %b %{Referer}i %{User-Agent}i" vhost
CustomLog logs/vhosts_access_log vhost

RewriteEngine on
#RewriteLog /usr/local/apache2/logs/rewrite_log
#RewriteLogLevel 9

RewriteMap lowercase int:tolower
RewriteMap vhost txt:/home/vhost.map

RewriteCond %{ENV:VHOST} ^$
RewriteCond %{REQUEST_URI} ^/~([^/]+)
RewriteCond ${lowercase:%1} ^(.+)$
RewriteRule ^.*$ $0 [PT,E=VHOST:%1]

RewriteCond %{ENV:VHOST} ^$
RewriteCond %{HTTP_HOST} !^$
RewriteCond ${lowercase:%{HTTP_HOST}} ^(.+)$
RewriteCond ${vhost:%1} ^(.+)$
RewriteRule ^.*$ $0 [E=VHOST:%1]

RewriteCond %{ENV:VHOST} !^$
RewriteCond %{REQUEST_URI} !^/~
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteRule ^/(.*)$ /~%{ENV:VHOST}/$1 [PT]

RewriteCond %{ENV:VHOST} !^$
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteRule ^/(.*)$ /~%{ENV:VHOST}/$1 [PT,T=application/x-httpd-cgi]

RewriteCond %{REQUEST_URI} ^/~[^/]+/cgi-bin/
RewriteRule ^.*$ $0 [PT,T=application/x-httpd-cgi]

<directory /home/*/public_html/>
    Options Indexes FollowSymLinks Includes
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>

<directory /home/*/public_html/cgi-bin>
    Options ExecCGI
    SetHandler cgi-script
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>
</pre>
<p>vhost.map内容为</p>
<pre class="brush: plain">
# domain name       # username
example.vhost       example
www.example.vhost   example
erning.vhost        erning
www.erning.vhost    erning
</pre>
<p>这样，启动apache后，就可以通过 http://www.example.vhost/ 访问 http://servername/~example/。 (设置了hosts文件，使.vhost后缀的域名可以使用)</p>
]]></content:encoded>
			<wfw:commentRss>http://erning.net/archives/linux-apache-vhost/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
