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

发布于 2024-12-26 05:32:38 字数 529 浏览 6 评论 0原文

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

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

需要做什么?

Currently I have 2 web applications app1 and app2 running on Tomcat 6:

I want to configure Tomcat so that they run in root context behind separate ports:

What needs to be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我是有多爱你 2025-01-02 05:32:38

我认为你可以在 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>

I think you can configure that in you server.xml file and put 2 services :

<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>
浅语花开 2025-01-02 05:32:38

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

<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

我建议阅读整个线程,因为它讨论了此配置的性能影响,以及可能的竞争条件。

Another example of adding connectors:

<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.)

Taken from: http://www.coderanch.com/t/84172/Tomcat/listen-multiple-ports

I recommend reading the whole thread, as it talks about performance hits with this configuration, and also possible race conditions.

最后的乘客 2025-01-02 05:32:38

除了运行两个 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>

Besides running two Tomcat instances and using ROOT application (that has already been said and is a bit poor and ineffective solution) you can achieve it by using Apache + Tomcat. Configuring apache to listen to both ports and forward by IP:Port to different Tomcat applications. But you need a different port for Tomcat!

Apache configuration

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>

or

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>
命硬 2025-01-02 05:32:38

使用两个不同的 Tomcat 实例。

编辑:

或者按照此问题的答案中的说明配置Tomcat: Tomcat 配置帮助:多个端口无响应

Use two different Tomcat instances.

EDIT:

Or configure Tomcat as explained in the answer of this question: Tomcat configuration help: multiple ports not responding

哭了丶谁疼 2025-01-02 05:32:38

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>

Tomcat runs on the ports specified in:

$CATALINA_HOME/conf/server.xml

As JB Nizet wrote, setup two different instances of tomcat, and configure the port value server.xml appropriately.

$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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文