How to Set Up server virtual hosts in Apache

Source: Internet
Author: User
Article Title: How to set up server virtual hosts under Apache. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I. Principles of WWW Server Virtual Host

A www server VM is a WWW server that uses a physical machine to act as multiple host names. For example, by a machine at the same time to provide http://www.company1.com, http://www.company2.com and other WWW services, and browse these WWW site users do not feel this way with different machines to provide different services.

The advantage of using WWW Virtual Hosts is that some small-scale websites share the same physical machine with other websites, which can reduce system operation costs and reduce management difficulty. In addition, individual users can also use this virtual hosting method to create WWW servers with their own independent domain names. Currently, many domestic companies provide this free service.

WWW Virtual Hosts can work in two ways:

1.1 IP address-based VM Mode

In this way, different host names are resolved to different IP addresses, and these IP addresses are set on the machines that provide the VM service. The server determines the Virtual Host Service requested by the user based on the target IP address of the user request, so as to further process the service.

Disadvantages: the IP address-based virtual host method requires that multiple IP addresses be set up on the machine that provides the virtual host service, which wastes IP addresses and limits the number of virtual hosts that a machine can accommodate. Therefore, this method is rarely used. However, this is the only way to use HTTP 1.0 to support virtual hosts.

1.2 host name-based VM

Because the IP address-based VM has the following disadvantages, the support for host name-based VM is added to HTTP 1.1. Specifically, when a client sends a request to the WWW server, the Host name that the client wants to access is also passed to the WWW server through the "Host:" statement in the request header. For example, www.company1.com and www.company2.com all correspond to the same IP address (that is, the same machine provides services for the two virtual domain names). When the customer program needs to access http://www.company1.com/index.html, the request header contains the following content:

GET/index.html HTTP/1.1

Host: www.company1.com

.....

After receiving the request, the WWW server program can check the "Host:" statement to determine the service of the virtual Host requested by the client program, and then further process the request.

Advantage: as long as one IP address is set on the machine that provides the VM service, theoretically it can provide services to countless virtual domain names, which consumes less resources and facilitates management. This method is basically used to provide the VM service.

Disadvantage: it cannot be used in earlier versions of HTTP 1.0. In fact, the current browser basically supports the host name-based virtual host mode.

Ii. Virtual Host setting technology under Apache server

2.1 Apache WWW server Overview

Apache WWW server is currently the most widely used WWW server software on the Internet. With flexible configuration, it can accomplish almost what you want. This article describes how to set up various virtual hosts in Apache.

2.2 IP address-based VM settings for Apache WWW Server

To use this virtual host method, you must first set an IP address for each virtual host on the server. These IP addresses can be completed by adding multiple NICs or setting up multiple IP addresses on one Nic. With multiple IP addresses, you can set Apache in either of the following ways:

2.2.1 run an Apache copy for each VM

In this way, each Apache program can be run by a single user, so each virtual host does not affect each other. When setting such a VM, you only need to set a configuration file for each Apache copy. The only thing you need to note is that you must use the "Listen" statement, each copy of Apache is forced to receive service requests only on its own IP address.

Advantage: each virtual host does not interfere with each other, and the security is high.

Disadvantage: it occupies a large amount of system resources.

2.2.2 multiple 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 when executing CGI programs, it may bring some serious security problems. When setting such a VM, you only need to set the following information for each VM:

       
        
         ; DocumentRoot /home/company1 …       ;
        
       

Advantage: less system resources are occupied than the previous method.

Disadvantage: low security. Each virtual host still needs one IP address.

2.3 simple name-based VM settings on the Apache WWW Server

[1] [2] Next page

Related Article

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.