Create a host name-based VM using Tomcat

Source: Internet
Author: User
Tags web hosting telnet program

Create a host name-based VM using Tomcat

(1) Use UltraEdit to open the Server under the <Tomcat main directory>/conf directory. in the xml file, use the "Search" menu to find the rows whose content is "</Host>", and add a pair of <Host> </Host> labels next to the row. Follow the preceding <Host> label attribute settings to set the new <Host> label attribute, and nest A <Context> element in it that sets the root directory of the WEB site, the final content is as follows:

<Host name = "site1" debug = "0" appBase = "d:/VirtualHost1">

<Context path = "" docBase = "." debug = "0"/>

</Host>

In this way, a new WEB site will be created. The docBase attribute value of the <Context> element above is set to a vertex (.), that is, the path set in the appBase attribute of the <Host> element is used as the directory mapped to the <Context> element.

(2) Add a <Host> </Host> label to the <Host> </Host> label and set it as follows:

<Host name = "site2" debug = "0" appBase = "d:/VirtualHost2">

<Context Path = "" docbase = "." DEBUG = "0"/>

</Host>

This creates a new web site. The host name of the site is Site2, and the local file system directory corresponding to the root directory is D:/virtualhost2.

(3) create a directory named virtualhost1and virtualhost2under D: and create a file named test.html separately in these two directories. Write the following line in the file D:/virtualhost1/test.html:

This isD:/virtualhost1Test.html file in the directory

Write the following line in the D:/virtualhost2/test.html file:

This isD:/virtualhost2Test.html file in the directory

(4) Save the modified server. xml file and restart the Tomcat web server program. Open a new command line window and execute the following command in this command line window:

Telnet fig 8080

In the telnet program command window, enter the following content:

GET/test.html HTTP/1.1 <press enter>

HOST: <space> Site1 <press enter>

<Press enter>

In the telnet program window, the body of the content returned by the WEB server is d:/VirtualHost1/test.html. Next, enter the following content under the content returned by the WEB server:

GET/test.html HTTP/1.1 <press enter>

Host: <space> site2 <press enter>

<Press enter>

In the telnet program window, the body of the content returned by the WEB server is d:/VirtualHost2/test.html. Next, enter the following content under the content returned by the WEB server:

GET/test.html HTTP/1.1 <press enter>

Host: <space> <press enter>

<Press enter>

In the telnet program window, you can see that the body of the content returned by the WEB server this time is the content in the d:/test/test.html file. Next, enter the following content in the content returned by the WEB server:

GET/test.html HTTP/1.1 <press enter>

Host: <space> xxx <press enter>

<Press enter>

In the telnet program window, you can see that the body of the content returned by the WEB server is still in the d:/test/test.html file.

As shown in figure 2.34 of the interaction process above, Tomcat searches for the Server based on the Host header value specified in the 1st and 2nd requests. the name attribute value of the matching <Host> element in the xml file, and responds with the WEB site set by the matching <Host> element; the value of the Host Header specified in the 3rd and 4th requests, in the Server. the name attribute value of the corresponding <Host> element does not exist in the xml file. Tomcat will respond with the default WEB site.

Fig 2.34

(5) in Windows 2000, use the Notepad program to open the c:/winnt/System32/Drivers/Etc/Hosts file. You can see the following line of content:

127.0.0.1 localhost

Next to this line of text, use it to copy two lines of text, and modify the localhost in the two lines of text to site1 and site2, respectively, the Hosts file is used to set multiple host names for the current computer. If you want to use the site1 and site2 host names to access WEB sites on other computers, you should change 127.0.0.1 to the actual IP address of other computers. After saving the Hosts file, run the "ping site1" and "ping site2" commands in the command line window to check whether the host name is correctly resolved to the corresponding IP address. After siting site1 and site2 to computer IP addresses, enter http: // localhost: 8080/test.html, http: // site1: 8080/test.html, and http: // site2: 8080/test.html. You can view the content of the test.html webpage file on each site.

 

It can be seen that when you create multiple virtual hosts on the same WEB server using the host name and use the host name in a WEB browser to access the Web server, the Web server selects the WEB site associated with the host name for response. In this way, multiple WEB sites can share the same IP address and the same port number. The only drawback is that WEB browsing cannot access these WEB sites through the IP address. Host Name-based virtual hosts are commonly used by most web hosting service providers on the Internet. You only need to find the websites of several small companies or individuals. If you enter "http: // host name" in the address bar of a WEB browser, you can access the website, run "ping host name" in the command line window to view the IP address of the domain name, and then enter "http: // ip address" in the address bar of the WEB browser, however, the website cannot be accessed. Therefore, the WEB site is a host name-based virtual host, which shares a WEB server with other WEB sites, rather than a dedicated WEB server.

Note:: When Secure Socket Layer (SSL) is used, the host header field cannot be used to implement the virtual host, because SSL-enabled HTTP requests are encrypted. The Host header field is part of the encrypted content and cannot be interpreted or routed to the correct site.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.