Tomcat 7 deploys two projects by setting up different ports
- 2020-05-17 07:09:17
- OfStack
The approach introduced in this article is to do this by adding a different port number. The method is as follows:
1. Modify.. /tomcat/conf/ server.xml, 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="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" 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 modify
Service 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="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps1" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" 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 the directory to deploy
../Tomcat/webapps1
, and copy the project that needs to be deployed to that directory;
b. Create a directory of configuration files
../Tomcat/conf/Catalina1/localhost
4. Modify the project code
In the process of trying to find a relatively easy to error, is the best to modify
web.xml
and
log4j.properties
Configuration files.
Among them
web.xml
File, need to be added
webAppRootKey
, the code is as follows:
// The upper node is web-app
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>mos_ms.root</param-value>
</context-param>
log4j properties, modified
log4j.appender.org.apache.log4j.DailyRollingFileAppender.File
, the code is as follows:
// The specific location is customizable, but needs to be in ${catalina1.home} In the
log4j.appender.A=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A.File=${catalina1.home}/logs/GYL_log/PurePro_
5. Make appropriate changes
Launch tomcat, the webapps directory and the webapps1 directory applications will be launched, according to different ports to access the inside of the project; Assuming that the project name is MyApp, for the above changes so we can use the following address access: http: / / localhost: 8080 / MyApp or http: / / localhost: 8090 / MyApp.
conclusion
The above is the entire content of this article, I hope the content of this article can bring 1 definite help to everyone's study or work, if you have any questions, you can leave a message to communicate.