Introduction to the server virtual host Setup method under Apache

Source: Internet
Author: User
Tags header advantage

The principle of WWW server virtual host

The WWW server virtual host refers to a WWW server that uses a physical machine to act as multiple host names. For example, by a machine to provide http://www.company1.com, http://www.company2.com and other WWW services, and browsing the WWW site users do not feel this way with the different machines to provide different services what is the difference.

The advantage of using the WWW virtual host is that some small web sites, by sharing the same physical machine with other sites, can reduce the operating costs of the system and reduce the difficulty of management. In addition, for individual users, can also use this virtual host to establish their own independent domain name of the WWW server, there are many companies in the country to provide this free service.

There are two ways of working with WWW virtual hosts:

1.1 Virtual host mode based on IP address

In this way, different host names are resolved to different IP addresses, and these IP addresses are set on the machine that provides the virtual host service. The server determines which virtual host services the user requests based on the destination IP address of the user's request, thus further processing.

Disadvantage: The virtual host based on the IP address needs to provide a virtual host service on the machine to set up multiple IP addresses, both waste the IP address, but also limits the number of virtual hosts a machine can hold. Therefore, this approach is used more and more sparingly. However, this approach is the only virtual host method supported by the HTTP 1.0 protocol that was used earlier.

1.2 Virtual host mode based on host name

The HTTP 1.1 protocol adds support for host-based virtual hosts because of the drawbacks of the virtual host approach based on IP addresses. Specifically, when a client program makes a request to the WWW server, the host name that the customer wants to access is also passed to the WWW server through the "host:" statement in the request header. For example, www.company1.com, www.company2.com all correspond to the same IP address (that is, the same machine to provide services to these two virtual domain names), the client program to access the http://www.company1.com/ When index.html, the request header that is issued contains the following contents:

Get/index.html http/1.1

Host:www.company1.com

.....

After the WWW server program receives this request, it can check the "host:" Statement to determine which virtual host the client request is a service, and then further processing.

Advantages: The provision of virtual host services on the machine as long as the setting of an IP address, theoretically can give countless multiple virtual domain names to provide services, less resources, management convenience. Currently, this is basically the way to provide virtual hosting services.

Disadvantage: Not available under earlier HTTP 1.0 versions. In fact, the browsers now in use basically support the host-based virtual host approach.

Two, the Apache server under the virtual host Setup technology

2.1 Apache WWW Server Introduction

The Apache www server is the most widely used WWW server software on the Internet today. With a flexible configuration, it can accomplish almost the functionality you want. This article mainly introduces the method of setting up various virtual hosts under Apache.

2.2 IP Address based virtual host settings under the Apache www server

With this type of virtual host, you first set up a separate IP address for each virtual host on the server. These IP addresses can be completed by adding multiple network adapters or by setting up multiple IP addresses on a single network card. With multiple IP addresses, you can set up Apache in one of the following two ways:

2.2.1 Run a copy of Apache for each virtual host

In this way, each Apache program can be run by a separate user, so each virtual host does not affect each other. When setting up this virtual host, just set up a set of configuration files for each Apache, the only thing to be aware of is that you must use the "Listen" statement to force each Apache to receive a service request only on its own IP address.

Advantages: Each virtual host between the mutual interference, high security.

Disadvantage: Occupy system resources more.

2.2. More than 2 virtual hosts share the same Apache

In this way, each virtual host shares the same Apache, so there is a certain impact between each virtual host, especially the execution of CGI programs, may bring some serious security problems. When you set up this virtual host, you can set up information similar to the following for each virtual host:

<VirtualHost www.company1.com>;
DocumentRoot /home/company1

</VirrualHost>;

Advantage: Less system resources than the previous one.

Disadvantage: Low security, each virtual host still needs to occupy an IP address.

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.