Running multiple Tomcat instances on the same port

I need to run multiple tomcat6 instances under different directory names on the same port. I will be installing tomcat6 twice for two different projects. But how do you configure both instances to run on the same port?

+3


source to share


6 answers


This can be accomplished with an apache web server that routes requests based on the application using mod_jk or mod_proxy. (and get an explanation on both extensions)



To choose which apache extension to use: apache to tomcat: mod_jk vs mod_proxy

+4


source


Yes, you can. In server.xml, replace:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->
    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

      

Through



<Host name="app1.com"  appBase="webappsApp1" unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

<Host name="app2.com"  appBase="webappsApp2" unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

      

In the webappsApp1 directory, you put the App1 war, same for the webappsApp2 and App2 directory.

The dns zone of App1 and App2 contains the public IP address of the server.

+2


source


It is not possible to start two services to serve on the same port. You can only run one code per port.

+1


source


Only one process can listen on a specific port at a time. Therefore, what you want to do is not directly possible. You might be in luck with forwarding requests to another instance, or using another server as an interface (like Apache).

+1


source


Yes, you can run multiple tomcat instances (or any other object) on the same port. To do this, you need to have multiple Real IPs limited by VIPs and each RIP can use its own listening port.

So, each tomcat will run on the same port, but on a different real IP.

0


source


Different instances with different contexts with the same port number:

  <!-- Test1 -->
  <Host name="192.168.1.254"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="254_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

  <!-- Test2 -->
  <Host name="192.168.1.250"  appBase="webapps1"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing2" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="250_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

  <!-- Test3 -->

  <Host name="192.168.1.249"  appBase="webapps2"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing3" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="249_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

      

0


source







All Articles