Multiple domain name binding of the same Tomcat

Keywords: Apache Tomcat xml Windows

Requirement: the same Tomcat

Objectives:

1. Access the project under the webapp of Tomcat through the localhost / project name
 2. Through www.aaa.com and www.bbb.com, visit the virtual hosts with different domain names under Tomcat

I. modify the port number under the server.xml file

II. Project location

3. Multi domain configuration

Copy and paste the information in the server. XML file into the label, and modify it as follows. The parameter name defaults to localhost, changes to your own domain name and adds a label between the labels, and the parameter path is your project ROOT directory. For example, if the project is empty directly under the tomcat, docBase is based on the appBase, and you can write the absolute path or the relative path , you can put the project in the ROOT folder, so that the address does not have the project name

In fact, the context tag only serves as a connection. It's ok if you don't use it. Just put the content of the project (i.e. the project name folder excluding the outer layer) directly under the ROOT to run. The effect is the same

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

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
		
		<!--<Context path="" docBase="hugh" debug="0" reloadable="true" crossContext="true" />-->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
	  
	  
	  <Host name="www.aaa.com"  appBase="aaa"
            unpackWARs="true" autoDeploy="true">
		<Context path="" docBase="ROOT\AAA" debug="0" reloadable="true" crossContext="true" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
	  
	  
	  <Host name="www.bbb.com"  appBase="bbb"
            unpackWARs="true" autoDeploy="true">
			<Context path="" docBase="ROOT\BBB" debug="0" reloadable="true" crossContext="true" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
	  
    </Engine>


IV. domain name resolution

Since you didn't buy a domain name, you can only use the stand-alone version by modifying the hosts file

Hosts path: C:\Windows\System32\Drivers\etc\hosts


V. make domain name resolution effective

Restart or run ipconfig /flushdns with cmd command


Six, test

Posted by genics on Wed, 04 Dec 2019 07:05:45 -0800