Run Multiple Instance of Apache Tomcat in Single Server

A 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" />
Code language: HTML, XML (xml)

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>
Code language: HTML, XML (xml)

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" />
Code language: HTML, XML (xml)

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" />
Code language: HTML, XML (xml)
Just change the above ports in your second installation of Tomcat.

View Comments

  • 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

  • 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?

    • 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..

  • 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

  • Hi Viral:
    How to pass these multiple connector through command line as environment variable.
    I have used as below.

    [code language="xml"]
    <Connector port="${CATALINA_BASE_PORT}" maxHttpHeaderSize="8192"
    maxThreads="500" minSpareThreads="150" maxSpareThreads="200"
    enableLookups="false" redirectPort="8443" acceptCount="200"
    connectionTimeout="300000" disableUploadTimeout="true"
    strategy="ms" socketBuffer="20480"/>

    <Connector port="${CATALINA_SECOND_BASE_PORT}" maxHttpHeaderSize="8192"
    maxThreads="300" minSpareThreads="100" maxSpareThreads="150"
    enableLookups="false" redirectPort="8443" acceptCount="200"
    connectionTimeout="-1" disableUploadTimeout="true"
    maxKeepAliveRequests="-1" strategy="ms" socketBuffer="20480"/>
    [/code]
    When i passed, it is giving error at shutdown time. Tomcat is failed to shutdown.

    Sriram.

Share
Published by
Viral Patel
Tags: apache tomcat Application Server How-To tomcat tomcat ports webserver

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

4 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

4 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

4 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

4 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

4 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

4 years ago