Tomcat : How to start Tomcat on more than one Port.
How to start Tomcat on more than one Port.
Tomcat settings can be found in TomcatFolder/conf/server.xml
file.
Root
element of the configuration isServer
tag.- You can add multiple
Service
underServer
tag for running tomcat on more than one port.
Default Service Configuration should look as follows
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
The above configurations states the folllowing things
Service name="Catalina"
- Service name isCatalina
, you can change it to give your application name.Connector port="8080" protocol="HTTP/1.1"
- Tomcat will run onport 8080
connectionTimeout="20000"
- Connection timeout in20000 mili seconds
Connector port="8009" protocol="AJP/1.3"
- AJP connection on port8009
.name="localhost"
- Name of the host where tomcat will run.appBase="webapp"
- Base directory for deployed apps iswebapp
unpackWARs="true"
- The war files deplyed wll be unpacked
Running Tomcat on multiple ports.
To start tomcat on more than one port you can add multiple Service
blocks under Server
root tag as shown below
<Service name="app1">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="app1"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="app1_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
<Service name="app2">
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8091" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="app2"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="app2_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
Here in above configuration we have specified the following.
- Service
app1
configuration will run on port8080
. - Service
app2
configuration will run on port8090
. app1
will keep files and war files in folderapp1
.app2
will keep files and war files in folderapp2
.app1
andapp2
will write access logs in folderlogs/app1_access_log.txt
andlogs/app2_access_log.txt
respectively
Note : None of the above configuration will keep files or war files in webapp folder.
Also Read
No comments: