【Yii2.0】1.4 Apache2.4.23基于主机名的虚拟主机配置

1.配置虚拟主机之前,我们先配置两个本地域名,打开C:\Windows\System32\drivers\etc\hosts,添加两个域名,同ip不同域名

2.新建两个目录,作为apache服务的根目录

3.找到D:\PHPServer\Apache24\conf\httpd.conf,502行,打开httpd-vhosts.conf配置

4.找到D:\PHPServer\Apache24\conf\extra\httpd-vhosts.conf,添加如下配置

<VirtualHost *:80>
    DocumentRoot "D:/PHPServer/Apache24/htdocs/test1"
    ServerName test1.local.com
    <Directory "D:/PHPServer/Apache24/htdocs/test1">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/PHPServer/Apache24/htdocs/test2"
    ServerName test2.local.com
    <Directory "D:/PHPServer/Apache24/htdocs/test2">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

需要说明的是,在2.4版本以前设置访问权限采用的是

Order allow,deny
Allow from all

 

但是2.4版本之后,这种方式不行了,正确的写法是

Require all granted

5.重启服务,访问http://test1.local.com和http://test2.local.com即可看到如下图效果

posted @ 2016-09-22 11:58  骑猪南下  阅读(494)  评论(0编辑  收藏  举报