Modify the port, modify the default publishing directory, and multi-domain name binding
1. Modify the publishing port number to 80 (Tomcat defaults to 8080)
Open the configuration file (mine is as follows: E:\J2EEServer\Tomcat 6.0\conf\), 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" />
After modification:
<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, just modify port:8080 to port:80, and other parameters remain unchanged. In this way, the client can directly enter the IP or domain name when accessing the server.
2. Modify the character set of tomcat
Everyone should have encountered the problem of Chinese garbled code in writing programs. In addition to ensuring that the character sets of pages and databases are consistent, there is one thing to note, that is, the character set of tamcat. Sometimes, from the beginning to the end, I found that the program was normal, but there was garbled code. Let’s take a look at Tomcat’s character set! Found E:\Tomcat 6.0\conf\:
<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" />
After modification:
<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 path: E:\J2EEServer\Tomcat 6.0\webapps\ROOT)
Open the configuration file (mine in: E:\J2EEServer\Tomcat 6.0\conf\), 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>
Add between the <host></host> 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 just enter the IP address to display the home page, the key value will be left blank;
docBase is the path to the virtual directory. Its default is the $tomcat/webapps/ROOT directory. Now I have created a photo directory under the webapps directory and let this directory be my default directory. debug and reloadable are generally set to 0 and true respectively.
In this way, when accessing the server, you will find the page under $tomcat/webapps/photo~~~~~~~
3. Multi-domain name binding
Open the configuration file (My name is as follows: D:\Program Files\Tomcat\conf\), 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>
Solution 1: Multiple projects in different directories
<Engine name="Catalina" defaultHost="pic.">
<Realm className=""
resourceName="UserDatabase"/>
<Host name="xixi." appBase="abcapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Engine name="Catalina" defaultHost="pic.">
<Realm className=""
resourceName="UserDatabase"/>
<Host name="xixi." appBase="abcapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="haha." appBase="D:\Program Files\Tomcat\test"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="lala." appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
<Host name="haha." appBase="D:\Program Files\Tomcat\test"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="lala." appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
The test adds the following content to the hosts file under C:\WINDOWS\system32\drivers\etc:
127.0.0.1 xixi.
127.0.0.1 lala.
127.0.0.1 haha.
Follow the above configuration:
1. http://xixi. Visit the website under ${tomcat}\abcapps\ROOT
2. http://haha. Visit the website under D:\Program Files\Tomcat\test\ROOT
3. http://lala. Visit the website under ${tomcat}\webapps\ROOT.
Engine's dafaultHost: It means to access the host that tomcat defaults to access. Note that it must not be localhost, otherwise others will access it through your IP and enter the tomcat management interface by default.
Host name: represents 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: represents the file storage path bound to the host, and can use relative or absolute paths.
Solution 2: Multiple projects are in the same directory webapps, that is, they are equipped with <Context> in different <host></host>
<Engine name="Catalina" defaultHost="xixi.">
<Realm className=""
resourceName="UserDatabase"/>
<Host name="xixi." appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="test1" debug="0" reloadable="true" />
</Host>
<Host name="haha." appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="test2" debug="0" reloadable="true" />
</Host>
<Host name="lala." appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="test3" debug="0" reloadable="true" />
</Host>