使用Tomcat部署加密虚拟主机,实现:
a.使用www.a.com域名访问的页面根路径为/usr/local/tomcat/a/base
b.使用www.b.com域名访问的页面根路径为/usr/local/tomcat/b/base
1. 修改server.xml配置文件,创建虚拟主机
[root@web1 ~]# vim /usr/local/tomcat/conf/server.xml
...
<Host name="www.a.com" appBase="a" unpackWARS="true" autoDeploy="true">
</Host>
<Host name="www.b.com" appBase="b" unpackWARS="true" autoDeploy="true">
</Host>
2. 创建虚拟主机对应的页面根路径
[root@web1 ~]# mkdir -p /usr/local/tomcat/{a,b}/base
[root@web1 ~]# echo "we are AAA" > /usr/local/tomcat/a/base/index.html
[root@web1 ~]# echo "we are BBB" > /usr/local/tomcat/b/base/index.html
3. 重启Tomcat服务器
[root@web1 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@web1 ~]# /usr/local/tomcat/bin/startup.sh
4. 客户端设置host文件解析域名,并测试页面
[root@client ~]# vim /etc/hosts
...
192.168.2.100 www.a.com www.b.com
[root@client ~]# firefox http://www.a.com:8080/ //访问域名a
[root@client ~]# firefox http://www.b.com:8080/ //访问域名b
5. 使用docBase参数可以修改默认网站首页路径. 假如,修改www.b.com的默认网站首页路径,可以这样做:
[root@web1 ~]# vim /usr/local/tomcat/conf/server.xml
...
<Host name="www.a.com" appBase="a" unpackWARS="true" autoDeploy="true">
</Host>
<Host name="www.b.com" appBase="b" unpackWARS="true" autoDeploy="true">
<Context path="" docBase="default"/> //定义首页目录为default
</Host>
...
[root@web1 ~]# mkdir /usr/local/tomcat/b/default
[root@web1 ~]# echo "we are default page" > /usr/local/tomcat/b/default/index.html
[root@web1 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@web1 ~]# /usr/local/tomcat/bin/startup.sh
结束.