Create a VM using Tomcat

Source: Internet
Author: User
Tags web hosting telnet program

After the web browser establishes a connection with Webserver, in addition to sending the resource path in the request URL to Webserver, it also sends the host name part in the URL as the host hair of the HTTP request message to webserver. For example, enter a http://www.it315.org in the browser's address bar and the content of the request message sent by the browser to the webserver on the www.it315.org host is as follows:

GET/HTTP/1.1 <press enter>

HOST: www.it315.org <enter>

<Press enter>

After the webserver receives the browser's Response Request message, it will know which web site to choose to respond to based on the host name set in the Host header field. Therefore, different host names can be used to identify different websites on the same webserver.

Tomcat server. the xml configuration file contains a

<Host name = "localhost" appbase = "webapps"…>

...

</Host>

The appbase attribute in the

When Tomcat receives a ghost request, the value of the Host header field in the ghost request message is compared with the name attribute value of the

<Engine name = "standalone" defaulthost = "localhost" DEBUG = "0">

...

<Host name = "localhost" appbase = "webapps"…>

...

</Host>

...

</Engine>

The configuration information above indicates that the default web site of the engine is the web site created by the

After multiple host name-based virtual hosts are created on the same computer, when a web browser asks the resources of a virtual host in the hosts file, the host name must be used in the hosts file, you cannot renew an IP address. This is because the Web Browser needs to send the host name part in the URL as the host hair of the HTTP request message to webserver. If the host name part in the URL uses an IP address, the value of the Host header field in the request message sent by the browser is the IP address, and multiple host name-based virtual hosts created on the same computer share the same IP address, using IP addresses in the Host header field cannot differentiate websites.

Even if the host name is specified in the URL, the Web browser must first obtain the IP address corresponding to the host name, and then use this IP address to connect to the webserver. Therefore, when creating a host name-based virtual host. in addition to settings in the XML file, you also need to establish a ing relationship between the host name and the IP address in the network system, that is, you must add the host name to the name resolution system, so that the Web browser can query the IP address corresponding to the host name from the name resolution system. There are two common ways to establish the ing between host names and IP addresses: one is to use the local hosts file of the client, and the other is to use the DNS (Domain Name System) server. The hosts file and DNS both allow users to use "friendly" host names in text format, rather than IP addresses in digital format to ask computers on the network. Hosts files can be used for small intranets (Enterprise intranets). hosts files must be used on all computers in the network. DNS is often used in large networks, especially computers that provide external services on the Internet. DNS is used to establish the ing between host names and IP addresses. The client first searches for the IP address mapped to the host name in the local hosts file. If no IP address is found, the client then queries the dnsserver. For the sake of simplicity, only the hosts file is described here. For Windows 2000, the hosts file is located in the system32/Drivers/etc sub-folder under the root folder of the operating system (which depends on the partition of the operating system, generally C:/WINNT, by default, the file contains the following line:

127.0.0.1 localhost

This line of text maps the IP address (127.0.0.1) to the Host Name (localhost), which is why localhost ghost can be used in the address bar of the IE browser to ask local webserver. If you want to add many other host names and IP address ing, you can add many other lines in the hosts file, then fill in the IP address and the corresponding host name in each line according to the format of the above line.

(1) Use ultraedit to open the server in the <Tomcat main folder>/conf folder. in the XML file, use the "Search" menu to find the rows with the content of " This isD:/virtualhost1 Test.html file in the folderWrite the following line in the D:/virtualhost2/test.html file: This isD:/virtualhost2 Test.html file in the folder(4) Save the modified server. xml file and start the Tomcat webserver program again. Open a new command line form and run the following command in the command line form: Telnet 127.0.0.1 8080, and then enter the following content in the successfully connected telnet program command form: GET/test.html HTTP/1.1 <press enter> HOST: <space> Site1 <press enter> you can see in the telnet program form that the body of the content returned by WebServer is D: the content in the/virtualhost1/test.html file. Then, enter the following content in the webserver: Get/test.html HTTP/1.1 <press enter> Host: <space> Site2 <press enter> you can see in the telnet program form that the body of the content returned by webserver this time is in the D:/virtualhost2/test.html file. Then, enter the following content in the webserver: Get/test.html HTTP/1.1 <press enter> Host: <space> <press enter> you can see in the telnet program form that the body of the content returned by webserver this time is the content in the D:/test/test.html file. Then, enter the following content in the webserver: Get/test.html HTTP/1.1 <press enter> Host: <space> XXX <press enter> the telnet program form shows that the body of the content returned by WebServer is still in the D:/test/test.html file. As shown in the previous interaction process 2.34, the Tomcat root finds the server based on the host header value specified in the 1st and 2nd requests. the name attribute value of the matching Note:: When Secure Socket Layer (SSL) is used, the host header field cannot be used to implement the virtual host. This is 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 website.

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.