假设我们把服务器架设在:/home/www文件夹下面
我们有应用A和B,对应的文件目录为
A:/home/www/testA
B:/home/www/testB
设置proxy_module让网站支持泛域名,好像这个是必须设置的,没试过去掉的情况
<IfModule proxy_module>
UseCanonicalName Off
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
</IfModule>
两个应用的泛域名支持:(这个可以写在httpd.conf, 也可以在httpd.conf中开启Include conf/extra/httpd-vhosts.conf之后写在httpd-vhosts.conf中)
testA
<Directory "/home/www/testA">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/home/www/testA"
ServerName testA.test.com
</VirtualHost>
testB
<Directory "/home/www/testB">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/home/www/testB"
ServerName testB.test.com
</VirtualHost>
如果一个文件夹下面有多个应用比如:
/home/www/someapp
/home/www/someapp/app1
/home/www/someapp/app2
/home/www/someapp/app3
我们可以这样设置:
<VirtualHost *:80>
DocumentRoot "/home/www/someapp/"
ServerName *.test.com
ServerAlias *.test.com
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/home/www/test.map
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1
AccessFileName .htaccess_test
</VirtualHost>
这里我们使用了test.map来进行域名的设置
test.map文件
app1.test.com /home/www/someapp/app1
app2.test.com /home/www/someapp/app2
app3.test.com /home/www/someapp/app3
这样当访问app1.test.com的时候就会自动指定到/home/www/someapp/app1文件夹下面