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