Use Apache to implement virtual host services

Source: Internet
Author: User
What is VM service the so-called VM service refers to virtualizing a machine into multiple WEB servers. For example, a company wants to provide host hosting services, which provides WEB services for other enterprises. Therefore, it certainly does not prepare a physical server for each enterprise, but uses a powerful large server, and then uses the Apache virtual host of the virtual host.

What is a VM service?

A virtual host service virtualizes a machine into multiple WEB servers. For example, a company wants to provide host hosting services, which provides WEB services for other enterprises. Therefore, it certainly does not prepare a physical server for each enterprise, but uses a large server with powerful functions and then uses a virtual host, it provides WEB services for multiple enterprises. although all WEB services are provided by this server, visitors can see that they have the same WEB services on different servers.

Specifically, we can use the VM service to store the home pages of www.company1.com and www.company2.com of two different companies on the same host. Visitors only need to enter the domain name of the company to access the homepage content they want.

You can use Apache to set up the VM service in two ways: IP address-based virtual host and name-based virtual host. The following describes their implementation methods. So that you can select the most appropriate implementation method in specific applications.

Set and implement IP address-based VM service


Prerequisites
 
In this way, you need to set the IP alias on the machine, that is, bind multiple

IP addresses are used to serve multiple VM instances. To use this function, make sure that the IP alias settings must be supported in your Linux kernel. Otherwise, you must re-compile the kernel.

The following is a service setting with two virtual hosts for your reference.

2. configuration steps

Assume that the machine we use to implement the VM service already provides the WEB service for ourselves. now we will provide the VM service for www.company1.com, a new company.

Planned IP address: apply for a new IP address for the VM. (Assume that the local IP address is 202.101.2.1)
 
Www.company1.com 202.101.2.2


2) enable the ISP to resolve the domain name.

3) set an IP alias for the NIC:

/Sbin/ifconfig eth0: 0 202.101.2.2 netmask 255.255.255.0

4) reset "/etc/httpd/conf/httpd. conf" and add the following to the file:

ServerAdmin webmaster@yourdomain.com

DocumentRoot/home/httpd/www.company1.com

ServerName www.company1.com

ErrorLog/var/log/httpd/www.company1.com/error.log


5) create a directory.

Mkdir/home/httpd/www.company1.com

Mkdir/var/log/httpd/www.company1.com/error.log
 

6) store the corresponding homepage content in the corresponding directory.

3. unfavorable factors

There is a serious deficiency in the implementation of such virtual hosts, that is, each time a virtual host is added, an IP address must be added. Because the IP address space is very tight, it is usually impossible to obtain so many IP addresses. In a sense, this is also a waste of IP addresses.

Set and implement name-based VM service

The name-based virtual host service is a suitable solution. Because it does not require more IP addresses and is easy to configure, there is no need for special hardware and software support. Most modern browsers support the implementation of such virtual hosts. Of course, this means that some early client browsers may not support the implementation of such virtual hosts.

There is no reason to use the IP address-based VM service instead of the name-based VM service. To configure the name-based VM service, you need to modify the configuration file: "/etc/httpd/conf/httpd. conf". add the following content to this configuration file.

NameVirtualHost 202.101.2.1

ServerAdmin webmaster@yourdomain.com

DocumentRoot/home/httpd/www.company1.com

ServerName www.company1.com

ErrorLog/var/log/httpd/www.company1.com/error.log

ServerAdmin webmaster@yourdomain.com

DocumentRoot/home/httpd/www.company2.com

ServerName www.company2.com

ErrorLog/var/log/httpd/www.company2.com/error.log


That is, add NameVirtualHost 202.101.2.1 based on the IP address-based configuration. In this example, two virtual host services are specially set to reflect the need to be added once.

Finally, you can create a directory to put the home page content in the corresponding directory.

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.