Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run different apps on single Tomcat instance behind different ports?

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

  • app1 on http://localhost:8080/app1
  • app2 on http://localhost:8080/app2

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

  • app1 on http://localhost:8081
  • app2 on http://localhost:8082

What needs to be done?

like image 701
DeeStackOverflow Avatar asked Jan 11 '12 16:01

DeeStackOverflow


People also ask

Can we run multiple applications in tomcat?

Simply drop both war files into Tomcat's webapps folder. That is all you need to do. By default, Tomcat expands ("explodes" some say) each war (technically a zip file) into a folder and automatically deploys the app for you. This happens on the fly if Tomcat is already running, or on startup when you launch Tomcat.

How many ports does Tomcat use?

By default the tomcat binding ports are 8005, 8080 and 8009. If you have another tomcat instance running on same server or other application like JBoss Application Server, these ports are likely already used. In this case you should change the default ports.


2 Answers

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> (...Repeted 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.

like image 31
speeves Avatar answered Oct 08 '22 08:10

speeves


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> 
like image 86
Benoit Marilleau Avatar answered Oct 08 '22 09:10

Benoit Marilleau