What is a virtual host service?
The so-called virtual host service refers to virtualizing one machine into multiple WEB servers. For example, a company wants to engage in providing hosting services and it provides WEB services to other businesses. Then it is definitely not to prepare a physical server for each enterprise, but to use a large and powerful server, and then use a virtual host to provide WEB services for multiple enterprises. Although all WEB services It is provided by this server, but it makes visitors look like they are getting WEB services on different servers.
Specifically, we can use virtual hosting services to store the homepage content of two different companies www.company1.com and www.company2.com on the same host. Visitors only need to enter the company's domain name to access the homepage content they want.
Using Apache to set up virtual host services, there are usually two solutions: virtual host based on IP address and virtual host based on name. Below we will introduce their implementation methods respectively. So that everyone can choose the most appropriate implementation method in specific applications.
Set up and implement a virtual host service based on IP address
Prerequisites for implementation
IP address to serve multiple virtual hosts. And to use this function, you must also make sure that your LINUX kernel must support the setting of IP aliases, otherwise you must recompile the kernel.
The following is a service setup with two virtual hosts for reference.
2. Configuration steps
Assume that the machine we use to implement virtual host service has first provided WEB services for itself, and will now provide virtual host services for a new company www.company1.com.
Plan IP address: Apply for a new IP address for the virtual host. (Assume that the local IP address is 202.101.2.1)
Www.company1.com 202.101.2.2
2) Let the ISP do the corresponding domain name resolution work.
3) Set the IP alias for the network card:
/sbin/ifconfig eth0:0 202.101.2.2 netmask 255.255.255.0
4) Reset "/etc/httpd/conf/httpd.conf" in the file Add in:
DocumentRoot /home/httpd/www.company1.com
ServerName www.company1.com
ErrorLog /var/log/ httpd/www.company1.com/error.log
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. Disadvantages
This virtual host implementation method has a serious shortcoming, that is, every time a virtual host is added, an IP address must be added. Since the IP address space is already very tight, it is usually impossible to obtain so many IP addresses. And in a sense, this is also a waste of IP addresses.