apache| Virtual host VI, using Apache to implement virtual host service
6.1 What is a virtual host service
The so-called virtual Host service means to virtual a machine into more than one Web server. For example, a company wants to engage in hosting services that provide Web services to other businesses. Then it is certainly not for every enterprise to prepare a physical server, but with a powerful large server, and then in the form of a virtual host to provide multiple enterprise Web services, although all Web services are provided by this server, But it makes visitors look like they're getting a Web service on a different server.
Specifically, we can use the virtual hosting service to store two different company www.company1.com and Www.company2.com's home page content on the same host. Visitors simply enter the company's domain name to access the content of the home page it wants.
There are usually two scenarios for setting up a virtual host service with Apache: a virtual host based on IP addresses and a virtual host based on a name, and here's how to implement them separately. So that we can choose the most suitable implementation method in the concrete application.
6.2 Setting up a virtual host service based on IP address
Implementation Prerequisites
This way you need to set the IP alias on the machine, which is to bind multiple
IP addresses to serve multiple virtual hosts. Also, use this feature to make sure that you have to support IP alias settings in your Linux kernel, or you will have to recompile the kernel.
Here is a set of two virtual host service settings for reference.
2. Configuration steps
Let's say that the machine we use to implement the virtual hosting service has already provided itself with a Web service and will now provide virtual hosting services for a new company, www.company1.com.
Planning IP Address: Request a new IP address for the virtual host. (assuming the native IP address is 202.101.2.1)
Www.company1.com 202.101.2.2
2 let ISP make the corresponding domain name resolution work.
4) Reset "/etc/httpd/conf/httpd.conf" to include in the file:
<virtualhost 202.101.2.2>
ServerAdmin webmaster@yourdomain.com
Documentroot/home/httpd/www.company1.com
ServerName www.company1.com
Errorlog/var/log/httpd/www.company1.com/error.log
</VirtualHost>
5) to establish the corresponding directory.
Mkdir/home/httpd/www.company1.com
Mkdir/var/log/httpd/www.company1.com/error.log
6 The corresponding home page content in the corresponding directory can be.
3. Adverse factors
The implementation of this virtual host has a serious problem, that is, each additional virtual host, you must add an IP address. Because the IP address space is already very tight, so many IP addresses are usually not available. And in a sense, this is also a waste of IP address.
6.3 Setting up a virtual host service based on name
And based on the name of the virtual Host service, is more suitable for the use of a scheme. Because it does not require more IP address, and configuration is simple, no special hardware and software support. Most modern browsers support the implementation of this virtual host. Of course, this means that some early client browsers may not support the implementation of this virtual host.
It is for this reason that we have no reason to use a virtual host service based on IP addresses instead of using a server-based virtual host service. Configuring a name-based virtual host service requires modifying the configuration file: "/etc/httpd/conf/httpd.conf", adding the following in this configuration file.
Namevirtualhost 202.101.2.1
<virtualhost 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
</VirtualHost>
<virtualhost 202.101.2.1>
ServerAdmin webmaster@yourdomain.com
Documentroot/home/httpd/www.company2.com
ServerName www.company2.com
Errorlog/var/log/httpd/www.company2.com/error.log
</VirtualHost>
That is, on the basis of the configuration based on IP address added: Namevirtualhost 202.101.2.1 just. In this case, two virtual host services have been specifically set up in order to reflect the need to add only one time.
Finally, it is necessary to set up the corresponding directory, the main page content in the corresponding directory to go.
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.