It's not a secret anymore!*
The moose likes Tomcat and the fly likes Different webapps on same instance of  tomcat on different ports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Different webapps on same instance of  tomcat on different ports" Watch "Different webapps on same instance of  tomcat on different ports" New topic
Author

Different webapps on same instance of tomcat on different ports

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
I have a web application deployed and running on Tomcat at port 8080. Shutdown port is 8005 and AJP Connector is on Port 8009. I want to deploy another application on SAME INSTANCE and run it at different port. Convinced that it is possible, I made following changes in my $CATALINA_HOME/conf/server.xml:

Uncommented following in the xml file:
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />

Now how to deploy my second application so that it listens to 8443 and not at 8080. Which ever application starts first takes 8080 and second application complains of busy port.

Can someone please tell me the procedure of configuring tomcat to run different applications on different ports?
Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
how to deploy my second application so that it listens to 8443


It is the connector that is going to listen at that port, not your application. 8443 is the default SSL port when Tomcat default server.xml is used so https requests will go there automatically.

Why do you have an AJP connector at all?

If you need to keep these two applications separate, consider using the virtual host capability with two different host names instead of different ports.

Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Another option is to set up two connectors, listening to the same port but on different IP numbers by adding the "address" attribute to the connector elements.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Thanks for your ideas. I tried configuring virtual hosts on Tomcat, but without success. I followed everything on this page. Created a directory named $CATALINA_HOME/conf/Catalina/cab and here is part of my server.xml:


I even put a ROOT.xml in this directory, even though Tomcat 5.5 doesn't have any.(It wasn't working without it as well!)
created a directory $CATALINA_HOME/webapps/cab also and copied a webapp in this directory. But when I give http://10.xxx.xxx.xxx:8080/cab/appname I get


Now what have I done wrong here! Any clues please.
Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you trying to create another host or just another app?

If you just want to create another webapp, you don't need to configure anything.

Simply create a cab directory in webapps and create a WEB-INF directory inside cab and you're done.
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Yes I am trying to create another host.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I run a number of hosts on a Tomcat instance. In my <Host tags I give a complete path for the appBase where you appear to be trying to use some sort of relative address.

Also note that the name attribute has to be the exact way the host is addressed in URLs - if you want to address http://www.cab.com then www.cab.com should be the name.

Your use of /cab/cabinetroot/resourcemanager is NOT addressing another host but an application to be found under a cab directory in the default host.

Bill
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi Bill

Thanks a ton for your response. After reading your answer I realized what an idiot I was trying to access the application with that URL. I was able to set up virtual host for my tomcat instance.

Thanks a lot.

Just for the sake of completeness of information on this thread:
If you are not using any web server, then you need to manage the host information also. In my case, I added following line to Hosts file on Windows XP. You can see more info here.



Now my URL is: http://cab:<port>/<appname>

Thanks
Abhishek
 
jQuery in Action, 2nd edition
 
subject: Different webapps on same instance of tomcat on different ports