Tomcat 5.5 配置多域名和多虚拟路径如下:
修改conf/server.xml中<Engine>部分的<Host>,每个<Host>...</Host>代表一个域名(包括localhost):
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="www.defaultweb.com">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="www.defaultweb.com" appBase="webapps_defaultweb" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" >
<Context path="" reloadable="true" docBase="c:/websdefaultweb" workDir="c:/websdefaultwebwork" />
<Context path="/VitrualPath" reloadable="true" docBase="c" workDir="c:/websdefaultwebworkVitualPath" />
</Host>
<Host name=www.anotherweb.com appBase="webapps_anotherweb" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" />
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" >
<Context path="" reloadable="true" docBase="c:websdefaultweb" workDir="c:/websdefaultwebwork" />
<Context path="/VitrualPath" reloadable="true" docBase="c" workDir="c:/websdefaultwebworkVitualPath" />
</Host>
</Engine>
从上述的配置文件中可以看出,这个配置共配置了两个域名(不包括localhost):www.defaultweb.com 和 www.anotherweb.com ,然后配置了localhost,使之与www.default.com 一样,这样输入IP地址就能跑到www.defaultweb.com 了。
同样还可以看出,www.defaultweb.com 配置了两个虚拟路径,一个是默认路径"/",另一个是"/VitrualPath",并且他们都分别指定了各自的网站所在的文件目录。(localhost与他的路径是一致的)。
但是,在配置www.anotherweb.com 时,为什么没有指定它的网站文件目录呢?这是利用了Tomcat的相对路径,appBase="webapps_defaultweb" 表示,这个网站的文件放在${Tomcat_Home}/webapps_defaultweb中。 你需要在${Tomcat_Home}/webapps_defaultweb中,建立ROOT文件夹,并在ROOT中放置你的网站。当然大家也可以直接用绝对路径配置,请参照www.default.com 的配置。当然,大家也可以看出www.anotherweb.com 并没有配置虚拟路径,大家如果需要的话,也可以自行配置。
PS:<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/> 这部分是Server.xml中本来就有的,大家没有必要动它。