Tomcat configures multiple domain names to access multiple projects

1. Two projects, the first is ROOT, the default project of Apache-tomcat, and the second project is named applet.

2. Modify the server.xml file of tomcat. The original code is as follows, where the appBase of the Host tag indicates that the subdirectories under this directory will be automatically deployed as applications. name is the default domain name/IP for accessing the project (localhost is 127.0.0.1).

Note: When no project is deployed, the Host tag in the Engine tag is as shown in the figure above; and generally after the project is deployed normally, as shown in the figure below, there is obviously a Context tag, and the docBase attribute refers to the absolute position of the project on disk , the path attribute refers to the project name that needs to be added after the domain name/IP when accessing the project (for example, path="" does not need to add the project name to access).

3. It can be seen that we can configure multi-domain/IP access to multi-projects and add multiple Host tags. The code after adding is as follows:

Note: The green arrows in the above figure point out the differences respectively; the first Host indicates that the domain name www.t2.com accesses the ROOT project (appBase="webapps/ROOT") under webapps, where the ROOT project is located in the docBase location Under (docBase="D:\..."), add /ROOT after the domain name to access (path="ROOT"), which is www.t2.com:8080/ROOT; Similarly, the second virtual host is accessed through www.t2.com .t1.com:8080/applet access. (Because I am lazy, I borrowed the ROOT project and did not modify the port. You can configure other projects yourself to try).

4. The domain name is configured by modifying the hosts file.

5. After starting the project, as shown in the following two figures, you can also set the path attribute of the Context tag to path="", and you don't need to add the project name to access. If you change the port to 80, you don't need to add the port access. is that port 80 is not occupied.

figure 1:

figure 2:

6. Configure the single application on the server, change the port to 80, add a Context tag to the default Host tag (as follows my Context tag), and then set the name attribute of the Host to the domain name, and other things remain unchanged, so that you can directly pass The domain name accesses your published project; if you do not configure the Context tag to point to your own project, it will access the tomcat default project ROOT.

<Context docBase="/usr/local/tomcat/apache-tomcat-9.0.7/webapps/applet" path="" reloadable="true" />

7. Label related, the server.xml file is a four-layer structure composed of Server->Service->Engine->Host->Context.

Service: A set of Engines, including the definition of the thread pool Executor and the connector Connector.
Engine: A collection of virtual hosts.
Host: That is, a virtual host (the so-called "a virtual host" can be simply understood as "a website").
Context: Web application, a Context is for a Web application.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324591588&siteId=291194637