在Tomcat中配置虚拟主机的方法分享
一、基于主机名的虚拟主机的配置方法
在tomcat的server.xml中添加如下语句:
复制代码
代码如下:
<span style="font-size:16px;"> <Host name="site1" appBase="D:/VirtualHost1">
<Context path="" docBase="."/>
</Host>
<Host name="site2" appBase="D:/VirtualHost2">
<Context path="" docBase="."/>
</Host>
</span>
然后打开C:/WINDOWS/system32/drivers/etc下的hosts文件,在里面添加上映射关系
复制代码
代码如下:
<span style="font-size:16px;"># For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
127.0.0.1 site1
127.0.0.1 site2
</span>
二、基于端口号的虚拟主机的配置方法
在tomcat的server.xml中添加如下语句
复制代码
代码如下:
<span style="font-size:16px;"><Service name="Tomcat-second">
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<Connector port="8001" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
<Engine name="Second" defaultHost="site1">
<Host name="site1" appBase="D:/VirtualHost1">
<Context path="" docBase="."/>
</Host>
<Host name="site2" appBase="D:/VirtualHost2">
<Context path="" docBase="."/>
</Host>
</Engine>
</Service></span>
摘自 geniusxiaoyu的专栏