Preface
Tomcat is very good as a java container, but there are still some small pitfalls that you can avoid. I will record this.
START
question
- URL path conflict after deploying multiple projects
Scenario description
There are two projects under projectA and projectB. Except for the management information interface, the rest of the two projects have security verification mechanisms.
Since the front-end separation is not done, static resources are also present in Java projects. When requesting interfaces in static resources, the package name is not written, such as login, js code splicing server ip + port + the currently set url (/login), and /projectA is not added before /login, so there is no problem in testing on the local machine. This problem will only exist when deploying. This is also a problem, and is solved below.
It's a normal project
Solution for scenario 2
Open the configuration file in tomcat and add the default access power of <Context> set as the server in the <Host> tag, so as to avoid the package name, but this method is extremely irregular and is not recommended.
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/ --> <!-- <Valve className="" /> --> <!-- Access log processes all example. Documentation at: /docs/config/ Note: The pattern used is equivalent to using pattern="common" --> <Valve className="" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/> </Host>
Code explanation
<Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/>
- path and doBase together represent the specified package path. For simplicity, you can directly uninstall docBase.
- Restart tomcat and test that ip+port can directly access resources in the package. However, when accessing resources in other packages, url ambiguity will occur. I originally wanted to access projectB, but mapped to projectA project. Only some URLs will have such problems.
Then our solution is to install another tomcat and only deploy projects that require direct path mapping
In this way, go back to the directory where tomcat is located and copy the cp command
$> cp -r tomcat8.5/ tomcat8.6/
Then move projectA in tomcat8.5 to tomcat8.6.
Delete the tomcat8.5
<Context path="" docBase="/usr/tomcat8.6/webapps/sc_edu" debug="0" reloadable="true"/>
In tomcat8.6, the following changes are required.
Change the corresponding port of shutdown to 8006, as long as it is different from tomcat8.5 and does not conflict with the port.
<Server port="8006" shutdown="SHUTDOWN">
Change the corresponding port request, the same principle as above
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
If the content in the <Host> tag is copied, it needs to be modified to the corresponding mapping path.
In this way, two tomcats can run at the same time, and start and close have no effect on each other.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.