Apache virtual host configuration in three ways: apache virtual host _ PHP Tutorial

Source: Internet
Author: User
Apache allows you to configure virtual hosts in three ways: apache virtual hosts. Apache configures virtual hosts in three ways. apache virtual host 1. based on IP1. assume that the server has an IP address of 192.168.1.10, use ifconfig to bind three I Apache virtual hosts to the same network interface eth0.

I. IP-based

1. assume that the server has an IP address of 192.168.1.10, and use ifconfig to bind three IP addresses to the same network interface eth0:

[Root @ localhost root] # ifconfig eth0: 1 192.168.1.11
[Root @ localhost root] # ifconfig eth0: 2 192.168.1.12
[Root @ localhost root] # ifconfig eth0: 3 192.168.1.13

2. modify the hosts file and add one of the three domain names to the file:

192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com

3. create a root directory for storing web pages on the VM. for example, create a folder named test11_test21_test3 under the/wwwdirectory, and separate the folder named 1.html#2.html#3.html.

/Www/test1/1.html
/Www/test2/2.html
/Www/test3/3.html

4. include the additional profile httpd-vhosts.conf in httpd. conf, and then write the following configuration in the httpd-vhosts.conf:


ServerName www.test1.com
DocumentRoot/www/test1/
  
Options Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow From All
 



ServerName www.test1.com
DocumentRoot/www/test2/
  
Options Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow From All
 



ServerName www.test1.com
DocumentRoot/www/test3/
  
Options Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow From All
 

5. as a result, each virtual host can access www.test1.com, www.test2.com, and www.test3.com respectively.

II. based on host name

1. set domain name ing to the same IP address and modify hosts:

192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com

2. as above, create a VM to store the root directory of the web page

/Www/test1/1.html
/Www/test2/2.html
/Www/test3/3.html

3. include the additional profile httpd-vhosts.conf in httpd. conf, and then write the following configuration in the httpd-vhosts.conf:

To use a domain name-based virtual host, you must specify the server IP address (and possible Port) to make the host accept the request. You can use the NameVirtualHost command for configuration. If all IP addresses on the server are used, you can use * as the parameter of NameVirtualHost. Specifying the IP address in the NameVirtualHost command does not enable the server to automatically listen to that IP address. The IP address must correspond to a network interface on the server.

The next step is to set Configuration block, The parameters are the same as those of the NameVirtualHost command. Each In the definition block, at least one ServerName command is provided to specify the servo host and one DocumentRoot command to indicate where the content of the host exists in the file system.

If you add a virtual host to an existing web server, you must also create Define a block. Specifically, ServerName and DocumentRoot should contain the same content as the global one and be placed at the beginning of the configuration file to assume the role of the default host.

NameVirtualHost *: 80

ServerName *

DocumentRoot/www/

ServerName www.test1.com

DocumentRoot/www/test1/

  

Options Indexes FollowSymLinks

AllowOverride None

Order allow, deny

Allow from all

  

ServerName www.test2.com

DocumentRoot/www/test2/

  

Options Indexes FollowSymLinks

AllowOverride None

Order allow, deny

Allow from all

  

ServerName www.test3.com

DocumentRoot/www/test3/

  

Options Indexes FollowSymLinks

AllowOverride None

Order allow, deny

Allow from all

  

4. as a result, each virtual host can access www.test1.com, www.test2.com, and www.test3.com respectively.

III. port-based

1. modify the configuration file

Change the original

Listen 80
Change
Listen 80
Listen 8080.


2. change the VM settings:


DocumentRoot/var/www/test1/
ServerName www.test1.com



DocumentRoot/var/www/test2
ServerName www.test2.com

Http://www.bkjia.com/PHPjc/1037989.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1037989.htmlTechArticleApache to configure virtual host three ways, apache virtual host 1, based on IP 1. assume that the server has an IP address of 192.168.1.10, use ifconfig to bind 3 I on the same network interface eth0...

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.