Configure a virtual host on Tomcat
Reprinted:
First prepare we will configure two virtual hosts, assume that the domain names are
Www.sentom1.net
Www.sentom2.net
For the convenience of testing, please in the client:
Win2k: // Winnt / System32 / Drivers / etc / hosts
Linux: / etc / hosts
Add the following content, then check if the two domain names are parsing correct.
192.168.0.1 www.sentom1.net
192.168.0.1 www.sentom2.net
Of course, in the production environment, it is not possible, and needs to be parsed in DNS on DNS.
Two Tomcat Install Tomcat installation is not in this discussion scope, 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>
You now access www.sentom1.net font> p>
Body>
Html>
Place the test.html file in Tomcat / WebApps1 / root, Tomcat / WebApps2 / root directory, then "www.sentom1.net" in the Tomcat / WebApps2 / root / test.html file content "www.sentom2 .NET ".
At this point, the pre-preparation work is done, and it is some physical activity.
Three configuration virtual hosts mentioned in front of the independent IP and shared IP. 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.sentom1.net virtual hosts
Open the Tomcat / conf / server.xml file, remove all the content between the Host element, and then add the following to the original location of the Host element.
Unpackwars = "true" autodeploy = "true"> Pattern = "Common" resolvehosts = "false" /> Directory = "logs" prefix = "SENTOM1_LOG." suffix = ". TXT" TimeStamp = "true" /> Host> Configure www.sentom2.net virtual hosts Add the following 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, respectively http://www.sentom1.net:8080/test.html http://www.sentom2.net:8080/test.html If the page content obtained is below, 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.sentom1.net What you are visiting is www.sentom2.net Four reference Http://jakarta.apache.org/tomcat/