Home > Backend Development > PHP Tutorial > Three ways to configure Apache virtual host, apache virtual host_PHP tutorial

Three ways to configure Apache virtual host, apache virtual host_PHP tutorial

WBOY
Release: 2016-07-13 09:45:53
Original
1263 people have browsed it

Three ways to configure Apache virtual host, 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 IPs on 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 three domain names corresponding to one of them:

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

3. Establish the root directory where the virtual host stores web pages. For example, create test1, test2, and test3 folders in the /www directory, which store 1.html, 2.html, and 3.html respectively

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

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

Three ways to configure Apache virtual host, apache virtual host_PHP tutorial
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
&g t;
Three ways to configure Apache virtual host, apache virtual host_PHP tutorial

5. You’re done, test each virtual host and visit www.test1.com, www.test2.com, www.test3.com respectively

2. Based on host name

1. Set the domain name to map to the same IP 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 the root directory of the virtual host to store the web page

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

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

In order to use domain-based virtual hosting, the server IP address (and possibly port) must be specified for the host to accept requests. It can be configured using the NameVirtualHost directive. If all IP addresses on the server are used, you can use * as the parameter for NameVirtualHost. Specifying an IP address in the NameVirtualHost directive does not cause the server to automatically listen on that IP address. The IP address set here must correspond to a network interface on the server.

The next step is to set the configuration block for each virtual host you create. The parameters of are the same as the parameters of the NameVirtualHost command. In each definition block, there will be at least a ServerName directive to specify which host to serve and a DocumentRoot directive to indicate where the contents of this host exist in the file system.

If you add a virtual host to an existing web server, you must also create a definition block for the existing host. The contents contained in ServerName and DocumentRoot should be consistent with the global ones, and should be placed at the front of the configuration file to play the role of the default host.

Three ways to configure Apache virtual host, apache virtual host_PHP tutorial 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

  

Three ways to configure Apache virtual host, apache virtual host_PHP tutorial

 4. 大功告成,测试下每个虚拟主机,分别访问www.test1.com、www.test2.com、www.test3.com

 

三、基于端口

1.  修改配置文件

  将原来的

    Listen 80
      改为
      Listen 80
      Listen 8080


2. 更改虚拟主机设置:

Three ways to configure Apache virtual host, apache virtual host_PHP tutorial
    DocumentRoot /var/www/test1/
    ServerName www.test1.com



    DocumentRoot /var/www/test2
    ServerName www.test2.com
Three ways to configure Apache virtual host, apache virtual host_PHP tutorial

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1037989.htmlTechArticleApache 配置虚拟主机三种方式,apache虚拟主机 一、基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个I...
Related labels:
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