SoFunction
Updated on 2025-03-08

Tomcat 7 deploys two projects by setting up different ports

The method introduced in this article is to add a different port number. The method is as follows:

1. Modify.../tomcat/conf/, the original code is as follows:

<Service name="Catalina">

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

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

 <Engine defaultHost="localhost" name="Catalina">

 <Realm className="">
 <Realm className="" resourceName="UserDatabase"/>
 </Realm>

 <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
 <Valve className="" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
 </Host>

 </Engine>
 </Service>

2. Add a new port number, the code is as follows:

Pay attention to modificationService name; Connector port; Engine name; Host appBase

<Service name="Catalina1">

 <Connector connectionTimeout="20000" port="8090" protocol="HTTP/1.1" redirectPort="8443"/>

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

 <Engine defaultHost="localhost" name="Catalina1">

 <Realm className="">
 <Realm className="" resourceName="UserDatabase"/>
 </Realm>

 <Host appBase="webapps1" autoDeploy="true" name="localhost" unpackWARs="true">
 <Valve className="" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
 </Host>

 </Engine>
 </Service>

3. Create a directory

a. Create a directory that needs to be deployed../Tomcat/webapps1, and copy the projects that need to be deployed to this directory;

b. Create a configuration file directory../Tomcat/conf/Catalina1/localhost

4. Modify the project code

During my attempt, I found a more error-prone place, which is the best modificationandConfiguration file.

inFile, need to be addedwebAppRootKey, the code is as follows:

//The upper layer node is a web-app&lt;context-param&gt;
 &lt;param-name&gt;webAppRootKey&lt;/param-name&gt;
 &lt;param-value&gt;mos_ms.root&lt;/param-value&gt;
 &lt;/context-param&gt;

,Revise.The value of the code is as follows:

//Customize the specific location, but it needs to be in ${}=. 
=${}/logs/GYL_log/PurePro_

5. Make corresponding changes

The applications that start tomcat, webapps directory and webapps1 directory will be started, and the projects inside can be accessed according to different ports; assuming the project name is MyApp, for the above changes, we can use the following address to access it: http://localhost:8080/MyApp or http://localhost:8090/MyApp.

Summarize

The above is the entire content of this article. I hope that the content of this article will be of certain help to everyone’s study or work. If you have any questions, you can leave a message to communicate.