在Tomcat中配置虚拟主机

有两种方式:一种是基于主机名的虚拟主机,另一种是基于端口号的虚拟主机。

一、基于主机名的虚拟主机的配置方法

在tomcat的server.xml中添加如下语句:

	<Host name="site1" appBase="D:\VirtualHost1">
		<Context path="" docBase="."/>
	</Host>
	<Host name="site2" appBase="D:\VirtualHost2">
		<Context path="" docBase="."/>
	</Host>


 

然后打开C:\WINDOWS\system32\drivers\etc下的hosts文件,在里面添加上映射关系

# 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


 

 

 

二、基于端口号的虚拟主机的配置方法

tomcatserver.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,c,windows,service,System,Path)