Apache 2.4 虚拟主机配置

说明:apache 2.4 已经不支持NameVirtualHost指令

1.修改httpd.conf配置文件

# vim /usr/local/apache/conf/httpd.conf

在其中添加虚拟主机目录,添加如下

Include conf/vhosts/*.conf

2.新建虚拟主机目录

# mkdir /usr/local/apache/conf/vhosts

3.在vhosts目录下新建虚拟主机配置文件即可,下面是一个范例

<VirtualHost *:80>
    ServerAdmin admin@123admin.com
    ServerName www.123admin.com
    DocumentRoot /var/www/123admin
    DirectoryIndex index.html index.htm index.php
    php_admin_value open_basedir /var/www/123admin/:/tmp/

    <Directory "/var/www/123admin">
        Options FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

注意上面的Require all granted,apcache 2.4新版增加的安全措施,默认在主配置文件httpd.conf是Require all denied,如果不加此行,网站打开会报403权限错误。解决的办法是在虚拟主机中增加如上行,或者修改主配置文件为Require all granted