Run Multiple Instance of Apache Tomcat in Single Server

multiple-apache-tomcatA lot of time we want to run multiple instances of Apache Tomcat server on a single machine. Generally this is done for creating a separate load balancer server for an application or install a different application independently.

This can be achieved easy by some configuration in Tomcat Server. We need to install a second instance of Tomcat and change few port in configuration files.

Open server.xml from /conf directory of your Tomcat installation folder. Change following ports in server.xml file.

Connector Port

This is the port where Apache Tomcat listen for the HTTP requests. By default this port is set to 8080. We can identify this Port inside server.xml by checking the following tag. Change the port to different value (for example 8081) and the second instance will listen the HTTP request on that port.

<connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" redirectPort="8443" />

Shutdown Port

This port is used when we try to shutdown the Apache Tomcat Server. We can identify this Port inside server.xml by checking the following tag.

<server port="8005" shutdown="SHUTDOWN">
</server>

AJP (Apache JServ Protocol) Connector Port

The Apache JServ Protocol (AJP) is a binary protocol that can conduct inbound requests from a web server through to an application server that sits behind the web server. We can identify this Port inside server.xml by checking the following tag.

<connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Redirect Port

Any redirection happening inside Apache Tomcat will happen through this port. In Apache TOMCAT there are two instance where redirectPort is mentioned. First one is for the Apache TOMCAT server and other one is for the AJP port. We can identify this Port inside server.xml by checking the following tag. Ensure that redirectPort should be same for AJP and HTTP protocol.

<connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<connector port="8100" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

Just change the above ports in your second installation of Tomcat.



7 Comments

  • kamran 16 November, 2010, 15:08

    any performance or other issue, if enabling tomcat on multiple ports for the same protocol.?

  • Jerson 15 February, 2011, 10:22

    Hi,
    Please help me out.I have Struts2 Application which works fine when I run in localhost…Somehow I am failed to run using Virtual host name…It comes to stating login page after then it cannot execute my action classes….I am try to google for the solution but nothing works out…Please help me on this issue…..

    If My application can work in localhost I assume it will works for virtual host also…Please advice me on what can be the possible cause…

    Many Thanks and Regards,

    Jerson

  • Phantom1024 7 September, 2012, 5:09

    Thank you very much for your post. It was so simple, even I could understand it.

  • Gary 27 September, 2012, 0:34

    Thank you for this useful post.

    Question: Should anything more be said about the CATALINA_HOME variable and how its setting influences one or the other instance of Tomcat?

    • Smily face 1 January, 2013, 12:46

      CATALINA_HOME should be the main apache-tomcat (simply say, the downloaded one) directory.
      CATALINA_BASE should be tomcat-instance_1 directory for instance 1
      CATALINA_BASE should be tomcat-instance_2 directory for instance 2 and so on..

  • daniel 9 April, 2013, 1:10

    Thanks! It works for me =)

  • Prachi 12 August, 2013, 20:44

    Hi

    I am trying to run 2 instances of tomcat on my machine. I installed them in two separate folders. And changed the ports in the server.xml for the second tomcat. When I try to start them, the first one to be started gets started. The second one to be started starts and then closes immediately. Is there anything that I am missing?

    Thanks
    Prachi

Leave a Reply

Your email address will not be published. Required fields are marked *

Note

To post source code in comment, use [code language] [/code] tag, for example:

  • [code java] Java source code here [/code]
  • [code html] HTML here [/code]

Current day month ye@r *