不同版本的apache通过httpd-vhosts.conf配置虚拟主机

一、修改http.conf,使用httpd-vhosts.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

二、在httpd-vhosts.conf中配置站点

apache-2.2.x配置虚拟机的内容:

NameVirtualHost 192.168.10.81:80


ServerAdmin [email protected]
directoryIndex  index.html index.php index.htm index.shtml login.php
ServerName 192.168.10.81
DocumentRoot /var/www/vhosts/wwwroot

    Options -Indexes

    AllowOverride All

    Order allow,deny
    Allow from all




==================================

apache-2.4.x配置虚拟机的内容:


ServerAdmin [email protected]
directoryIndex  index.html index.php index.htm index.shtml login.php
ServerName 192.168.10.81
DocumentRoot /var/www/vhosts/wwwroot

    Options -Indexes

    AllowOverride All

    Require all granted



可以看到apache-2.4.x把NameVirtualHost给取消,现在配置虚拟主机不需要再配置NameVirtualHost了.
删除了 Order deny,allow 和 Order allow,deny
把 Deny from all 替换成了 Require all denied
把Allow from all 替换成了 Require all granted
然后还把 Allow from 192.168.10.21 这样的语句给替换成了 Require host 192.168.10.21

三、浏览器绑定host即可

你可能感兴趣的:(apache,服务器)