tomcat 6.0 配置多个端口    



一、Tomcat 安装后本身提供了一个server,端口配置默认是8080,对应目录为:..\Tomcat 6.0\webapps    



二、Tomcat 6.0 配置多个端口,其实也就是给Tomcat增加几个server,并设置对应目录。  



下面以增加两个端口号为例    



第一步、修改server.xml[..\Tomcat 6.0\conf]   



(1)Tomcat提供的如下:  



<Service name="Catalina">
<Connector port="8090"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8009"   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
</Host> </Engine>
</Service>



 (2)比着上面的葫芦画下面的瓢、新增两个端口号,注意Service name、Engine name、appBase,  当然了,端口号别忘了修改,以免重复。



<Service name="Catalina1">
<Connector port="8091"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8009"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3" />
<Engine name="Catalina1" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps1" unpackWARs="true" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false"></Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="8092"
maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8009"   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Engine name="Catalina2" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps2" unpackWARs="true" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false"></Host>
</Engine>
</Service>



 第二步、创建相应的部署目录 ..\Tomcat 6.0\webapps1 
                     ..\Tomcat 6.0\webapps2  
  同时可以将Tomcat 6.0\webapps下的有用的复制到新建的部署目录 
第三步、创建配置文件目录和配置文件 
..\Tomcat 6.0\conf\Catalina1\localhost
..\Tomcat 6.0\conf\Catalina2\localhost 
host-manager.xml manager.xml  配置文件的配置可参照..\Tomcat 6.0\conf\Catalina\localhost下的,只需要修改一下对应目录即可  
大概的配置步骤就是这些,现在可以把不同的war包放在不同的位置来访问了 以上配置方法同样适合Tomcat 5.5  。
Tomcat6 配置多虚拟主机,多域名绑定一IP 
实现效果: 
http://localhost 访问一个项目例如一个系统1。 
http://localhost1 访问一个项目例如一个系统2 
实现方案,需要修改两个地方  
一个是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>



 问题:1.  报 Caused by: Caught exception while loading file struts-default.xml 错     
解决:  删除lib下的xerces-2.6.2.jar