首页 > 代码库 > apache2.4.27配置虚拟主机
apache2.4.27配置虚拟主机
1:在httpd.conf中,把这行打开
Include conf/extra/httpd-vhosts.conf
2:进到conf/extra/里,修改httpd-vhosts.conf
原文件是这样的
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com (邮箱)
DocumentRoot "/web/www1" (发布目录)
ServerName www.luo.com (域名)
ServerAlias www.luo2.com (这可配置多域名)
ErrorLog "logs/dummy-host.example.com-error_log" (日志)
CustomLog "logs/dummy-host.example.com-access_log" common(日志)
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/web/www2"
ServerName www.luo1.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
这样配置好后还是打不开,显示无权限
乍一看没有问题,可是在apache-2.4.37下这样配置完,无权限访问。根据提示查看了目录以及文件的权限问题,没有问题;查看程序错误日志和系统日志也没有明显的错误;这时冷静下来好好想了想,目录及文件权限没有问题,那剩下就是站点目录访问权限了,于是在虚拟主机配置文件里面的虚拟主机配置前加入这么一段:
<Directory "虚拟主机站点目录">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
配置文件如下
<Directory "/web">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/web/www1"
ServerName www.luo.com
ServerAlias www.luo2.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/web/www2"
ServerName www.luo1.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
经过以上的修改后,重启Apache服务,现在可以正常访问
本文出自 “luojinsheng” 博客,请务必保留此出处http://3774912.blog.51cto.com/3764912/1948908
apache2.4.27配置虚拟主机