搞了Tomcat6配置多虚拟主机很久,终于OK了。
真是够吐血的,记录下来,方便以后查阅了。
实现效果:
http://localhost 访问一个项目例如一个助学网。
http://localhost1 访问一个项目例如一个办公系统
实现方案,需要修改两个地方
一个是C:\WINDOWS\system32\drivers\etc\hosts文件,改为
127.0.0.1 localhost
127.0.0.1 localhost1
另一个要改的就是server.xml,修改后如下:
- <?xml version= '1.0' encoding= 'utf-8' ?>
- <Server port= "8005" shutdown= "SHUTDOWN" >
- <Listener className= "org.apache.catalina.core.AprLifecycleListener" SSLEngine= "on" />
- <Listener className= "org.apache.catalina.core.JasperListener" />
- <Listener className= "org.apache.catalina.mbeans.ServerLifecycleListener" />
- <Listener className= "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
- <GlobalNamingResources>
- <Resource name= "UserDatabase" auth= "Container"
- type= "org.apache.catalina.UserDatabase"
- description= "User database that can be updated and saved"
- factory= "org.apache.catalina.users.MemoryUserDatabaseFactory"
- pathname= "conf/tomcat-users.xml" />
- </GlobalNamingResources>
- <Service name= "Catalina" >
- <Connector port= "80" protocol= "HTTP/1.1"
- connectionTimeout= "20000"
- redirectPort= "8443" />
- <Connector port= "8009" protocol= "AJP/1.3" redirectPort= "8443" />
- <Engine name= "Catalina" defaultHost= "localhost" >
- <Realm className= "org.apache.catalina.realm.UserDatabaseRealm"
- resourceName= "UserDatabase" />
- <Host name= "localhost" appBase= "webapps"
- unpackWARs= "true" autoDeploy= "true" debug= "0" >
- <Context path= "" docBase= "E:\Tomcat6\webapps\YangFan\" reloadable=" true " crossContext=" true "/>
- </Host>
- <Host name= "localhost1" appBase= "webapps"
- unpackWARs= "true" autoDeploy= "true" debug= "0" >
- <Context path= "" docBase= "E:\Tomcat6\webapps\hiccOffice\" reloadable=" true " crossContext=" true "/>
- </Host>
- </Engine>
- </Service>
- </Server>