The Tomcat website publishes a detailed description of the configuration plan

  • 2020-05-30 20:56:20
  • OfStack

Modify the port, modify the default distribution directory, multiple domain name binding

1. Change the publish port number to 80 (Tomcat is 8080 by default)

Open the configuration file (mine is as follows: E:\J2EEServer\Tomcat 6.0\conf\ server.xml) and find:


<Connector port="8080" protocol="HTTP/1.1"  

              maxThreads="150" connectionTimeout="20000"   

              redirectPort="8443" />    
<Connector port="8080" protocol="HTTP/1.1"

             maxThreads="150" connectionTimeout="20000"

             redirectPort="8443" />

Revised:


<Connector port="80" protocol="HTTP/1.1"   

              maxThreads="150" connectionTimeout="20000"   

              redirectPort="8443" />   
<Connector port="80" protocol="HTTP/1.1"

             maxThreads="150" connectionTimeout="20000"

             redirectPort="8443" />

In fact, we can just change port:8080 to port:80, and the other parameters will remain unchanged. This allows the client to enter either IP or the domain name directly when accessing the server.

2. Modify the tomcat character set

In addition to ensuring that the character set of the page and database is kept at 1, there is still one point to be noted, that is, the character set of tamcat. Sometimes I check the sequence from beginning to end, and find that program 1 is normal, but there is a messy code, look at the Tomcat character set! Find E:\Tomcat 6.0\conf\server.xml:


<Connector port="80" protocol="HTTP/1.1"   

              maxThreads="150" connectionTimeout="20000"   

              redirectPort="8443" />   
<Connector port="80" protocol="HTTP/1.1"

             maxThreads="150" connectionTimeout="20000"

             redirectPort="8443" />

Revised:


<Connector port="80" protocol="HTTP/1.1"   

              maxThreads="150" connectionTimeout="20000"    

              redirectPort="8443" URIEncoding="UTF-8"/>   
<Connector port="80" protocol="HTTP/1.1"

             maxThreads="150" connectionTimeout="20000" 

             redirectPort="8443" URIEncoding="UTF-8"/>

3. Modify the tomcat publishing path (default: E:\J2EEServer\Tomcat 6.0\webapps\ROOT)
Open the configuration file (mine is at: E:\J2EEServer\Tomcat 6.0\conf\ server.xml) and find:


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

<Host name="localhost"   appBase="webapps"   

             unpackWARs="true"   

             xmlValidation="false" xmlNamespaceAware="false">          

</Host>    

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

<Host name="localhost"  appBase="webapps"

            unpackWARs="true"

            xmlValidation="false" xmlNamespaceAware="false">      

</Host>

</Engine>

in < host > < /host > Add between tags:


<Context path="" docBase="photo" debug="0" reloadable="true" />   
<Context path="" docBase=" Project path " debug="0" reloadable="true" />

path is the name of the virtual directory. If you want to display the home page by entering only the ip address, the key value is left blank.

docBase is the path to the virtual directory, which defaults to the $tomcat/webapps/ROOT directory. Now I have set up an photo directory under webapps and have it as my default directory. debug and reloadable1 are generally set to 0 and true, respectively.

This way, when you visit the server again, you will find the page under $tomcat/webapps/photo ~ ~ ~ ~ ~ ~



3. Multiple domain name binding

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


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

<Host name="localhost"   appBase="webapps"   

             unpackWARs="true"   

             xmlValidation="false" xmlNamespaceAware="false">          

     </Host>    

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

<Host name="localhost"  appBase="webapps"

            unpackWARs="true"

            xmlValidation="false" xmlNamespaceAware="false">      

    </Host>

</Engine>

Option 1: multiple projects in different directories


<Engine name="Catalina" defaultHost="pic.ofstack.com">    

     <Realm className="org.apache.catalina.realm.UserDatabaseRealm"   

              resourceName="UserDatabase"/>    

   

     <Host name="xixi.ofstack.com"   appBase="abcapps"   

             unpackWARs="true"   

             xmlValidation="false" xmlNamespaceAware="false">    

</Host>   
<Engine name="Catalina" defaultHost="pic.ofstack.com">

    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

             resourceName="UserDatabase"/>

 

    <Host name="xixi.ofstack.com"  appBase="abcapps"

            unpackWARs="true"

            xmlValidation="false" xmlNamespaceAware="false"> 

</Host>

 
     <Host name="haha.ofstack.com"   appBase="D:\Program Files\Tomcat\test"   

             unpackWARs="true"   

             xmlValidation="false" xmlNamespaceAware="false">    

</Host>    

   

     <Host name="lala.ofstack.com"   appBase="webapps"   

             unpackWARs="true"   

             xmlValidation="false" xmlNamespaceAware="false">    

     </Host>    

</Engine>   
<Host name="haha.ofstack.com"  appBase="D:\Program Files\Tomcat\test"

            unpackWARs="true"

            xmlValidation="false" xmlNamespaceAware="false">

</Host>

 

    <Host name="lala.ofstack.com"  appBase="webapps"

            unpackWARs="true"

            xmlValidation="false" xmlNamespaceAware="false">

    </Host>

</Engine>

The following is added to the hosts file under C:\WINDOWS\system32\drivers\etc:

127.0.0.1 xixi.ofstack.com

127.0.0.1 lala.ofstack.com

127.0.0.1 haha.ofstack.com

Follow the above configuration:

1. http: / / xixi. ofstack. com access ${tomcat} \ abcapps \ ROOT website

2. http: / / haha. ofstack. com access D: \ Program Files \ Tomcat \ test \ ROOT under web site

3. http: / / lala. ofstack. com access ${tomcat} \ webapps \ ROOT website.

Engine's dafaultHost: indicates the host that accesses tomcat by default. Please note that 1 must not be localhost, otherwise others will enter tomcat's management interface by default if they access ip.

name of Host: represents the domain name bound to the host, which can be accessed by entering localhost in the browser if bound to localhost.

appBase of Host: represents the file storage path bound to this host, which can be either relative or absolute.


Option 2: multiple projects under the same 1 directory webapps, i.e. in different < host > < /host > With inside < Context >


<Engine name="Catalina" defaultHost="xixi.ofstack.com">    

     <Realm className="org.apache.catalina.realm.UserDatabaseRealm"   

         resourceName="UserDatabase"/>    

   

     <Host name="xixi.ofstack.com"   appBase="webapps"   

         unpackWARs="true"   

         xmlValidation="false" xmlNamespaceAware="false">    

        <Context path="" docBase="test1" debug="0" reloadable="true" />    

</Host>    

   

<Host name="haha.ofstack.com"   appBase="webapps"   

         unpackWARs="true"   

         xmlValidation="false" xmlNamespaceAware="false">    

        <Context path="" docBase="test2" debug="0" reloadable="true" />    

</Host>    

   

<Host name="lala.ofstack.com"   appBase="webapps"   

         unpackWARs="true"   

         xmlValidation="false" xmlNamespaceAware="false">    

        <Context path="" docBase="test3" debug="0" reloadable="true" />    

</Host> 


Related articles: