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

4nkexdtk  于 2023-10-19  发布在  其他
关注(0)|答案(5)|浏览(154)

目前我有两个web应用程序app1和app2运行在Tomcat 6上:

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

需要做些什么?

u0njafvf

u0njafvf1#

我认为你可以在你的server.xml文件中配置它,并放置2个服务:

<Service name="app1">
   <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" 
           connectionTimeout="20000" 
           redirectPort="8443" />
   <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost"  appBase="app1"
        unpackWARs="true" autoDeploy="true">
      </Host>
   </Engine>
</Service>
<Service name="app2">
   <Connector port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol" 
           connectionTimeout="20000" 
           redirectPort="8443" />
   <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost"  appBase="app2"
        unpackWARs="true" autoDeploy="true">
      </Host>
   </Engine>
</Service>
hfwmuf9z

hfwmuf9z2#

添加连接器的另一个示例:

<Service name="reciver">
    <Connector port                  ="8080"
               maxHttpHeaderSize     ="8192"
               maxThreads            ="10"
               enableLookups         ="false"
               acceptCount           ="100"
               connectionTimeout     ="10000"
               disableUploadTimeout  ="true"
               useBodyEncodingForURI ="true"
    />
    <Engine name        ="reciver"
            defaultHost ="localhost"
            jvmRoute    ="host1"
    >
        <Realm className    ="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName ="UserDatabase"
        />
        <Host name              ="localhost"
              appBase           ="webapps"
              unpackWARs        ="true"
              autoDeploy        ="false"
              xmlValidation     ="false"
              xmlNamespaceAware ="false"
        >
            <Context docBase    ="browser"
                     path       ="/browser"
                     reloadable ="false"
            />
        </Host>
    </Engine>
</Service>

<Service name="reciver2">
    <Connector port                  ="8081"
               maxHttpHeaderSize     ="8192"
               maxThreads            ="10"
               enableLookups         ="false"
               acceptCount           ="1"
               connectionTimeout     ="10000"
               disableUploadTimeout  ="true"
               useBodyEncodingForURI ="true"
               proxyName             ="example.pt"
               proxyPort             ="80"
    />
    <Engine name        ="reciver2"
            defaultHost ="example_app"
            jvmRoute    ="host2"
    >
        <Host name              ="example_app"
              appBase           ="test_app/example_app"
              unpackWARs        ="true"
              autoDeploy        ="false"
              xmlValidation     ="false"
              xmlNamespaceAware ="false"
        >
            <Context docBase    ="example_app"
                     path       ="/example_app"
                     reloadable ="false"
            />
        </Host>
    </Engine>
</Service>

(...Repeated 2 more times.)

来源:http://www.coderanch.com/t/84172/Tomcat/listen-multiple-ports
我建议阅读整个线程,因为它讨论了这种配置的性能影响,以及可能的竞争条件。

hts6caw3

hts6caw33#

除了运行两个Tomcat示例和使用ROOT应用程序(已经说过了,这是一个有点差和无效的解决方案),你可以通过使用Apache + Tomcat来实现它。配置apache监听两个端口并通过IP:Port转发到不同的Tomcat应用程序。但是你需要一个不同的Tomcat端口!
Apache配置

listen 8080,8081
...
<VirtualHost *:8080>
    ServerName localhost
    ProxyPass / http://localhost:8888/app1
    ProxyPassReverse / http://localhost:8080/app1
</VirtualHost>

<VirtualHost *:8081>
    ServerName localhost
    ProxyPass / http://localhost:8888/app2
    ProxyPassReverse / http://localhost:8080/app2
</VirtualHost>

listen 80,81
...
<VirtualHost *:80>
    ServerName localhost
    ProxyPass / http://localhost:8080/app1
    ProxyPassReverse / http://localhost:8080/app1
</VirtualHost>

<VirtualHost *:81>
    ServerName localhost
    ProxyPass / http://localhost:8080/app2
    ProxyPassReverse / http://localhost:8080/app2
</VirtualHost>
lmvvr0a8

lmvvr0a84#

使用两个不同的Tomcat示例。
编辑:
或者按照这个问题的答案配置Tomcat:Tomcat configuration help: multiple ports not responding

0s7z1bwu

0s7z1bwu5#

Tomcat运行在以下文件中指定的端口上:

$CATALINA_HOME/conf/server.xml

正如JB Nizet所写的,设置两个不同的tomcat示例,并适当地配置端口值server.xml。
$CATALINA_HOME/tomcat-8081/conf/server.xml

<?xml version='1.0' encoding='utf-8'?>
    <Server port="8081" ... >
        ...
    </Server>

$CATALINA_HOME/tomcat-8082/conf/server.xml

<?xml version='1.0' encoding='utf-8'?>
    <Server port="8082" ... >
    ...
    </Server>

相关问题