Configure different access ports for multiple applications in tomcat

Configure different access ports for multiple applications in tomcat ...
Configure different access ports for multiple applications in tomcat

Open tomcat installation directory and check conf/server.xml

<?xml version="1.0" encoding="UTF-8"?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.core.AprLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/> <GlobalNamingResources> <Environment name="simpleValue" type="java.lang.Integer" value="30"/> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <!--Note: modification<Connector>Inside port --> <Connector port="8099" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" /> <Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <!--Note: configure the web Directory path --> <Context path="/demo2" docBase="D:/java/projects/demo2/WebRoot" reloadable="true" /> </Host> </Engine> </Service> </Server> Add an application and set the access port to 8098 <Service name="Catalina1"> <!--Note: modification<Connector>Inside port --> <Connector port="8098" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" /> <Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> <Engine name="Catalina1" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <!--Note: configure the web Directory path --> <Context path="/demo1" docBase="D:/java/projects/demo1/WebRoot" reloadable="true" /> </Host> </Engine> </Service>

Starting tomcat can be accessed as follows:

http://localhost:8099/demo2/index.jsp

http://localhost:8098/demo1/index.jsp

* note that the place to be changed is the place to be noted. There are appBase = "webapps" in the other two applications. This is the default directory under tomcat. All applications in this directory can be accessed through these two ports (8099, 8098). If you don't want to be accessed by both ports, you can modify appBase, for example: appBase = "webapps2", But you need to create a new webapps2 directory under the tomcat installation directory.

31 May 2020, 10:02 | Views: 1120

Add new comment

For adding a comment, please log in
or create account

0 comments