猿问

如何在不同端口后面的单个Tomcat实例上运行不同的应用程序?

目前,我有2个Web应用程序app1和app2在Tomcat 6上运行:


APP1上的http://本地主机:8080 / APP1

APP 2上的http://本地主机:8080 / APP 2

我想配置Tomcat,以便它们在根上下文中在单独的端口后面运行:


http:// localhost:8081上的app1

http:// localhost:8082上的app2

需要做什么?


慕码人2483693
浏览 433回答 3
3回答

繁花不似锦

我认为您可以在server.xml文件中进行配置,并放置2个服务:<Service name="app1">&nbsp; &nbsp;<Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connectionTimeout="20000"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;redirectPort="8443" />&nbsp; &nbsp;<Engine name="Catalina" defaultHost="localhost">&nbsp; &nbsp; &nbsp; <Host name="localhost"&nbsp; appBase="app1"&nbsp; &nbsp; &nbsp; &nbsp; unpackWARs="true" autoDeploy="true">&nbsp; &nbsp; &nbsp; </Host>&nbsp; &nbsp;</Engine></Service><Service name="app2">&nbsp; &nbsp;<Connector port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connectionTimeout="20000"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;redirectPort="8443" />&nbsp; &nbsp;<Engine name="Catalina" defaultHost="localhost">&nbsp; &nbsp; &nbsp; <Host name="localhost"&nbsp; appBase="app2"&nbsp; &nbsp; &nbsp; &nbsp; unpackWARs="true" autoDeploy="true">&nbsp; &nbsp; &nbsp; </Host>&nbsp; &nbsp;</Engine></Service>

千巷猫影

除了运行两个Tomcat实例并使用ROOT应用程序(已经说过,这是一种较差且无效的解决方案)之外,您还可以使用Apache + Tomcat来实现。配置apache侦听两个端口并通过IP:Port转发到不同的Tomcat应用程序。但是您需要使用tomcat的其他端口!Apache配置listen 8080,8081...<VirtualHost *:8080>&nbsp; &nbsp; ServerName localhost&nbsp; &nbsp; ProxyPass / http://localhost:8888/app1&nbsp; &nbsp; ProxyPassReverse / http://localhost:8080/app1</VirtualHost><VirtualHost *:8081>&nbsp; &nbsp; ServerName localhost&nbsp; &nbsp; ProxyPass / http://localhost:8888/app2&nbsp; &nbsp; ProxyPassReverse / http://localhost:8080/app2</VirtualHost>要么listen 80,81...<VirtualHost *:80>&nbsp; &nbsp; ServerName localhost&nbsp; &nbsp; ProxyPass / http://localhost:8080/app1&nbsp; &nbsp; ProxyPassReverse / http://localhost:8080/app1</VirtualHost><VirtualHost *:81>&nbsp; &nbsp; ServerName localhost&nbsp; &nbsp; ProxyPass / http://localhost:8080/app2&nbsp; &nbsp; ProxyPassReverse / http://localhost:8080/app2</VirtualHost>
随时随地看视频慕课网APP

相关分类

Java
我要回答