Tomcat Learning Notes (iv)--Virtual Hosting

Source: Internet
Author: User
Tags hosting port number tomcat

One, host name-based virtual host

Network environment:

1. When a browser accesses a host name-based virtual host, the access URL must be in the host name and cannot use the IP address

2. The mapping between host name and IP address must be established in the whole network system

2.1 Using the local Hosts file to establish a mapping relationship between host name and IP (C:\Windows\System32\drivers\etc\Hosts)

127.0.0.1 www.andgoo.cn

127.0.0.1 www.pds.cn

2.2 Using DNS (for money)

Use the command line to ping localhost and www.pds.cn after you have set up the hosts file to ping the

The virtual directory structure for creating two virtual hosts is as follows:

F:\web

| ——— + VM1

| ————— +root

| ———————— +web-inf

| ———————— +index.html

| ——— + VM2

| ————— +root

| ———————— +web-inf

| ———————— +index.html

Modify the Server.xml file

Add the following code directly in the <Engine> element of the Server.xml file

 
 

Test:

1. Restart Tomcat

2. Browser testing:

Url:http://www.andgoo.cn:8080/index.html

Url:http://www.pds.cn:8080/index.html

Second, based on the port number of the virtual host

Configuration principle:

1. A <Connector> element is used to configure an external connector, and for each listening port number of the Web server, configure a separate <Context> element

2. A <Connector> element corresponding connector must have a <Engine> element associated

3. How one or more <Context> elements are associated with <Engine> elements: nesting <Context> elements with <Engine> elements in the same <Service> element

Configuration method:

Add another <Services> element inside the <Server> element of the Server.xml file

  <service name= "Secend-serv" >    <connector port= "Up" protocol= "http/1.1"                 connectiontimeout= "20000"                 redirectport= "8443"/>                     <engine name= "Catalina" defaulthost= "www.andgoo.cn" >              

Attention:

1. The name attribute of the <Service> element must be different from the original <Service> name and therefore modified to: Secend-serv

2. The port property of the <Engine> element is modified to 80 (or any other port you want not to be occupied)

3. The Defaulthost property of the <Engine> element is modified to the value of the Name property of the included one <Host> property, and I choose www.andgoo.cn

4. This section I did not test success, is trying to ...

Third, IP address-based virtual host

1. HTTP 1.0 does not support the host field, when the site unified use of port 80, people can only use a different IP address to establish a virtual host

Disadvantage: Each virtual host consumes a ip,ip consume serious

2. HTTP 1.1 can establish multiple Web sites with different host names, so providers typically no longer establish IP address-based virtual hosting services

3. Tomcat does not provide IP address-based virtual hosting mode

Zhang Xiaoxiang Teacher's test method is as follows (I can not test with the following methods, do not know why):

1. CMD command line run: telnet localhost 8080

2. Ctrl +], then enter

3. get/test.html http/1.1

Host: hostname

Description: Host name is not written, default is localhost

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.