I need to run multiple instances of tomcat6 under different directory names on the same port. I will install tomcat6 twice for two different projects. But how to configure both the instances to run on the same port?
You could realise this using an apache webserver that is directing the 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
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 "%r" %s %b" />
</Host>
By
<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 "%r" %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 "%r" %s %b" />
</Host>
In the webappsApp1 directory you put the war of App1, the same for webappsApp2 directory and App2.
In dns zone of App1 and App2 put the public ip of the server.
Its impossible to run two service to serve via single port. You can only run one tomcat per port number.
Only one process can listen at a certain port at a time. So what you want to do is not directly possible. You may have luck with forwarding requests to the other instance, or using another server as front end (for example Apache).
Yes you can run multiple instances of tomcat ( or any other object ) on same port. For this you need to have multiple Real IP bounded to VIP and then each RIP can use their own set of port to listen.
So, each tomcat will run on same port but on different Real IP address.
Different Instances with different Context with 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 "%r" %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 "%r" %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 "%r" %s %b" />
</Host>
来源:https://stackoverflow.com/questions/26093298/running-multiple-instances-of-tomcat-on-same-port