How to start Tomcat on more than one Port.
Tomcat settings can be found in TomcatFolder/conf/server.xml file.
Rootelement of the configuration isServertag.- You can add multiple
ServiceunderServertag 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 8080connectionTimeout="20000"- Connection timeout in20000 mili secondsConnector 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 iswebappunpackWARs="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
app1configuration will run on port8080. - Service
app2configuration will run on port8090. app1will keep files and war files in folderapp1.app2will keep files and war files in folderapp2.app1andapp2will write access logs in folderlogs/app1_access_log.txtandlogs/app2_access_log.txtrespectively
Note : None of the above configuration will keep files or war files in webapp folder.
Also Read
Comments
Post a Comment