一.在Tomcat下配置一个应用服务(service)中,配置多个端口号。
即一个service配置多个端口,项目可以通过多个端口访问。
修改tomcat-homeconf下的server.xml,在Service下配置多个<Connector>即可。
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Connector port="8099" protocol="HTTP/1.1" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" URIEncoding="utf-8"
disableUploadTimeout="true" />
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>‘
在这个应用里,可以用8080端口号访问服务,也可以用8099端口号来访问服务; 服务放置的路径由host决定,上例中服务放在webapps下。
即,以下两种方式访问同一个项目:
http://localhost:8080/项目名称
http://localhost:8099/项目名称
二、在一个Tomcat下配置多个服务,用不同的端口号。
即配置多个service,每个service可以配置多个端口。
修改tomcat-homeconf下的server.xml,添加多个Service即可。
注意Service name、Engine name、appBase,端口号别忘了修改,以免重复
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>
<Service name="Catalina1">
<Connector connectionTimeout="20000" port="8099" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina1">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps1" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector connectionTimeout="20000" port="8098" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina2">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps2" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>
以上三个service,发布的路径不同,项目分别发布在webapps、webapps1、webapps2下,
访问不同的项目的方法:
http://localhost:8080/项目名称1
http://localhost:8099/项目名称2
http://localhost:8088/项目名称3