在一个Tomcat下配置多个服务,用不同的端口号。
即在配置文件中配置多个service,每个service可以配置多个端口。
修改tomcat-home\conf下的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="8081" 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="8082" 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:8081/项目名称2
http://localhost:8082/项目名称3
把多个项目放到一个tomcat中容易整体歇菜,建议一个tomcat发布一个项目;
-----------------------------------------
一台机器运行多个tomcat行,容易发生端口冲突,需要更改端口,需要改的有三个地方:
tomcat\conf下的server.xml
1.<Server port="8005" shutdown="SHUTDOWN"> 默认第22行
2.<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" /> 默认第69-71行
3.<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" /> 默认第117-120,默认注释了,可以不改