Configure a virtual host on Tomcat
We will configure two virtual hosts, assume that the domain names are www.aaa.Netww.bbb.net for easy test, please in the client: Win2k: // Winnt / System32 / Drivers / etc / hostslinux: / etc / hosts file Increase the following content, then check if the two domain names are parsing correct.
192.168.0.1 www.aaa.net
192.168.0.1 www.bbb.net
Of course, in the production environment, it is not possible, and needs to be parsed in DNS on DNS.
Two Tomcat installation
Tomcat installation is not discussed in this article, please refer to
Here
. Make sure the Tomcat is installed correctly, otherwise do not continue the following configuration steps. Copy a WebApps directory in the Tomcat directory in the same directory, and the directory name is divided into WebApps2 and then rename the WebApps directory as WebApps1. Finally, Tomcat's directory structure is as follows:
Tomcat
| --bin
| --Common
| --CONF
| --LOGS
| - Server
| --Shared
......
| --Webpapps1
| --Webpapps2
| - Work
Finally, write a simple HTML file for testing, file named Test.html, the file content is as follows:
HEAD>
Three configuration virtual hosts The IP of independent IP and shared is mentioned earlier. This article describes shared IP mode, which is all virtual hosts that use the same IP. The virtual hosts provided by China IDC are both models. The advantage of this mode is that the amount of IP is limited, and the disadvantage is that the virtual host can only access domain names and cannot be accessed through IP (in fact, it is not a disadvantage, only a little impact on the user's access in the mail system). And another independent IP mode is mainly used in the mail service, and it will not be introduced here. Configure www.aaa.net virtual hosts to open Tomcat / conf / server.xml files, remove all between the Host elements, and then add the following to the original location of the Host element. Unpackwars = "true" autodeploy = "true"> Directory = "logs" prefix = "SENTOM1_ACCESS_LOG." Suffix = ". TXT" pattern = "common" resolvehosts = "false" /> Directory = "logs" prefix = "SENTOM1_LOG." suffix = ". TXT" TimeStamp = "true" /> Host> Configure www.bbb.net virtual hosts to append the content below to the Host element, pay attention to changes in the Name property and the value of the AppBase property in the Host element. Unpackwars = "true" autodeploy = "true"> Directory = "Logs" prefix = "SENTOM2_ACCESS_LOG." suffix = ". txt" Pattern = "Common" resolvehosts = "false" /> Directory = "Logs" prefix = "SENTOM2_LOG." suffix = ". txt" TimeStamp = "true" /> Host> Now you can start Tomcat, visit http://www.aaa.net:8080/test.htmlhtp:8080/test.bb.net:8080/test.html, if the page content is below, then It shows that the virtual host has been configured successfully. Otherwise, check your configuration process and re-configure it according to documentation. What you are visiting is www.aaa.net What you are visiting is www.bbb.net Four reference http://jakarta.apache.org/tomcat/