LetsSyncUp
LetsSyncUp

Reputation: 4353

How to deploy multiple web application in tomcat which will run on different ports?

How to deploy multiple java web application in tomcat which will run on different ports ? - How to do settings so that different web application will run on different ports - What all needs to be done for achieving this?

Upvotes: 13

Views: 43328

Answers (4)

Flamenco13
Flamenco13

Reputation: 21

You can use mod-proxy in apache to redirect the custom port to the standard one.

mod proxy

Upvotes: 2

Dennis
Dennis

Reputation: 757

Sorry about making this an answer. I don't see any commenting ability for me on this question. Mabye the question is too old or my reputation is not high enough.

However, I have been researching the same question myself. You will have to know a lot more about how Tomcat, http servers, and the Java system environment to use the same instance. I have read where it is also VERY slow also.

The best bet is separate instances. There are two fairly easy ways to do that: A/ For Ubuntu, you can use SVN to get this script: http://ubuntuforums.org/showthread.php?t=1211517 http://code.google.com/p/tomcat-linux/

B/ Your own, per user instances. http://brian.pontarelli.com/2007/09/17/multiple-tomcat-instances-on-ubuntu/

The last one was written for tomcat 5.5, but is probably adaptable to Tomcat 6

However, the best directions for multiple JVM instances for the latest Tomcat on Linux is here: http://www.puschitz.com/InstallingTomcat.html

Upvotes: 4

Sean
Sean

Reputation: 7747

You will need to setup another service in your server.xml file (tomcat_home/conf). If you havent changed your server file, you should already have one named Catalina (I am using Tomcat 5.5, you may have something slightly different depending on version)

<Service name="Dev2">
    <Connector port="8090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    <Connector port="8092" 
               enableLookups="false" redirectPort="9443" protocol="AJP/1.3" />

    <Engine name="Dev2" defaultHost="MyDev">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
      <Host name="MyDev" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
      </Host>
    </Engine>
</Service>

Notice that the names have changed from Catalina to Dev2, and localhost to MyDev. Change these to whatever you seem fit for your application. The ports and connectors have also changed. Once the new Service is setup, you then need to deploy applications to the proper Service/Port. You accomplish this by using XML files under (See Virtual Hosting )

Tomcat_Home/conf/Catalina/localhost/

and

Tomcat_Home/conf/Dev2/MyDev/

for the respective ports which you are setting up

At this point all you have to do is add a few more files to point the Service to your application. As an Example, under Tomcat_Home/conf/Dev2/MyDev/ I have a file called Another.xml This file contains the following

<Context path="/" docBase="C:/to_delete" debug="10" crossContext="false">
</Context>

Now I can access the new application using the web address http://127.0.0.1:8090/Another If I try and access this using my default port of 8080, I get an error as the application was not deployed for that given port.

Few things to note about this setup. If you use VirtualVM to look at the application, you will notice that they share the same process ID. Therefore you have to be extra careful of your resources. They will be using the same Heap space, and all the threads will be showing in the same list. If you have logging in your applications (i.e Log4j) ensure you have an option to show which thread was doing the work, as it may be tough to tell otherwise which port/application this would be coming from.

As Bozho has already pointed out, It may be easier to simply have two instances of Tomcat running instead of one server listening on multiple ports.

Upvotes: 7

Bozho
Bozho

Reputation: 597362

You'd better have multiple tomcat installations. It would be easier.

I guess you can register multiple <Connector>s in server.xml, and then filter out the contexts, but that's tedious and sounds wrong.

Upvotes: 4

Related Questions