Using Apache to implement virtual host service_PHP tutorial

WBOY
Release: 2016-07-13 17:12:22
Original
845 people have browsed it

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:

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 the corresponding 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. 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.

http://www.bkjia.com/PHPjc/629445.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629445.htmlTechArticleWhat 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 for...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template