在网上找了半天也没找到相关的资料,都说的太含糊.
本人对tomcat下配置 一ip对多域名的方法具体例如以下,按以下配置一定能成功,经过測试了.
<Host name="localhost" debug="0" appBase="D://Tomcat 5.0//webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>localhost.com</Alias> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/> <Context path="" docBase="D://Tomcat 5.0//webapps//gg" reloadable="true" caseSensitive="false" debug="0"></Context> </Host> <Host name="one.localhost" debug="0" appBase="D://Tomcat 5.0//webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>one.localhost.com</Alias> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/> <Context path="" docBase="D://Tomcat 5.0//webapps//kk//a" reloadable="true" caseSensitive="false" debug="0"></Context> </Host> <Host name="two.localhost" debug="0" appBase="D://Tomcat 5.0//webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>two.localhost.com</Alias> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/> <Context path="" docBase="D://Tomcat 5.0//webapps//kk//b" reloadable="true" caseSensitive="false" debug="0"></Context> </Host>
因无域名解析server,所以在hosts上配,来模拟dns解析.
10.1.1.241 localhost 指向gg目录
10.1.1.241 localhost.com 指向gg目录
10.1.1.241 one.localhost 指向a目录
10.1.1.241 one.localhost.com 指向a目录
10.1.1.241 two.localhost 指向b目录
10.1.1.241 two.localhost.com 指向b目录
经过多方面尝试,最终在tomcat下配置成功了.
改动默认的应用时:改defaulthost,并将context的path置为空。
配置多个应用时:
相应的配置例如以下:
<Host name="localhost" debug="0" appBase="D://Tomcat 5.0//webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>localhost.com</Alias> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/> <Context path="" docBase="D://Tomcat 5.0//webapps//Root" reloadable="true" caseSensitive="false" debug="0"></Context> <Context path="/first" docBase="D://Tomcat 5.0//webapps//first" reloadable="true" caseSensitive="false" debug="0"></Context> <Context path="/second" docBase="D://Tomcat 5.0//webapps//second" reloadable="true" caseSensitive="false" debug="0"></Context> </Host>