Use tomcat to run multiple java projects with different domain names on one host

background:

Recently I wanted to engage in several different network projects. However, I was shy and didn't have enough money to shop for multiple cloud servers. So I tried to deploy multiple java projects on one host, so I used Tomcat to try this job. A lot of detours were also taken during the process, and finally several java projects were run on one cloud host. Of course, the visits of this project are not particularly large. If partners with the same needs can learn from it, they can also provide better solutions. There are not many sharing times, please forgive me if it is not good.
 
Environment:
    Tomcat 8.0 + jdk 8 

Steps

1. Modify the release port number to 80 (Tomcat defaults to 8080): In fact, here is to change port: 8080 to port: 80, other parameters remain unchanged. In this way, the client can directly enter the IP or domain name when accessing the server to
     open the configuration file (even as follows: D: \ Program Files \ Tomcat \ conf \ server.xml) and find:
<Connector port = "8080" protocol = " HTTP / 1.1 "
               maxThreads =" 150 "connectionTimeout =" 20000 "
               redirectPort =" 8443 "/>
After modification:
<Connector port =" 80 "protocol =" HTTP / 1.1 "
               maxThreads =" 150 "connectionTimeout =" 20000 "
               redirectPort = "8443" />

2. Modify the tomcat release path (default path: D: \ Program Files \ Tomcat \ webapps \ ROOT)

    Open the configuration file (even as follows: D: \ Program Files \ Tomcat \ conf \ server.xml) and find:

<Engine name="Catalina" defaultHost="localhost">
    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false"> 
  
    </Host>

</Engine>

Add between the <host> </ host> tags: <Context path = "" docBase = "apps" debug = "0" reloadable = "true" />. change into:

<Engine name="Catalina" defaultHost="localhost">
    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false"> 
          <Context path="" docBase="apps" debug="0" reloadable="true" />
    </Host>

</Engine>

path is the name of the virtual directory. If you want to display the homepage only by entering the ip address, the key value is left blank;
docBase is the path of the virtual directory, which defaults to the $ tomcat / webapps / ROOT directory, now I am in webapps An apps directory is built under the directory, and let this directory be the default directory.
debug and reloadable are generally set to 0 and true respectively.
Restart the server and find the items under $ tomcat / webapps / apps when accessing the server

3.
    Open the configuration file for multiple domain name binding (even as follows: D: \ Program Files \ Tomcat \ conf \ server.xml), find:

<Engine name="Catalina" defaultHost="localhost">
    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">     

    </Host>
</Engine>

change into:

<Engine name="Catalina" defaultHost="www.hpu56.cn">  
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>  
    <Host name="app.hpu56.cn"  appBase="hpu56"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">  
    </Host>
    <Host name="www.hpu56.cn"  appBase="D:\project\hpu56"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
    </Host>

    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
    </Host>

</Engine>

Engine's dafaultHost: means to access the host that the tomcat enters by default.Note that it must not be localhost, otherwise others will access the tomcat management interface by default.

Host name: indicates the domain name bound to the host.If you bind localhost, you can access the Host by typing localhost in the browser.

Host's appBase: indicates the file storage path bound to the host, you can use a relative path or an absolute path.

The operation is complete.

After the operation restarts Tomcat, multiple projects start successfully, and you can access the pages of multiple projects through the browser.

1. If I enter http: // localhost in the browser, I visit the website under D: \ Program Files \ Tomcat \ webapps \ apps
2. If I enter http://www.hpu56.cn, I visit D: \ Program Files Website under \ Tomcat \ hpu56 \ ROOT
3. If you enter http://app.hpu56.cn, you can visit the website under D: \ project \ hpu56 \ ROOT. 

Published 14 original articles · won 13 · visited 1717

Guess you like

Origin blog.csdn.net/D102601560/article/details/102753516