一、基于主机名的虚拟主机
在tomcat的server.xml中添加:
复制代码 代码示例:
<Host name="site1" appBase="D:VirtualHost1">
<Context path="" docBase="."/>
</Host>
<Host name="site2" appBase="D:VirtualHost2">
<Context path="" docBase="."/>
</Host>
然后打开C:WINDOWSsystem32driversetc下的hosts文件,在里面添加上映射关系:
复制代码 代码示例:
# For example:
#
# 102.54.94.97 rhino.jb200.com # source server
# 38.25.63.10 x.jb200.com # x client host
127.0.0.1 localhost
127.0.0.1 site1
127.0.0.1 site2
二、基于端口号的虚拟主机
在tomcat的server.xml中添加:
复制代码 代码示例:
<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>
看来tomcat配置虚拟主机很简单啊,就是修改配置文件就行了。