首页 > 开发 > Apache > 正文

apache2.4跟2.2配置虚拟主机区别

2020-07-28 15:06:32
字体:
来源:转载
供稿:网友
  用过Apache2.4的朋友一定没发现它和Apache2.2的有什么区别,其实一些基本配置都是差不多,我就是在配置虚拟主机时才能发现一些小差别。
 
  我在htdocs目录下配置虚拟主机的,大体上使用的方法如下:
 
  <VirtualHost*:80>
 
  DocumentRoot"D:/www/Apache24/htdocs"
 
  ServerNamelocalhost
 
  <DirectoryD:/www/Apache24/htdocs>
 
  DirectoryIndexindex.htmlindex.php
 
  OrderDeny,Allow
 
  Allowfromall
 
  </Directory>
 
  </VirtualHost>
 
  但是最近我想在目录htdocs之外配置虚拟主机,还是按照上面的老套路来配置,结果出现的403错误:
 
  Forbidden
 
  Youdon'thavepermissiontoaccess/onthisserver.
 
  瞬间没了头绪,这是在Apache2.2所没有的出现过的情况啊,然后试着将虚拟主机的根目录改成htdocs目录之下,也就是
 
  DocumentRoot"D:/www/Apache24/htdocs/test"
 
  发现网站又能正常运行了,反复试了多次都是同一的结果。然后我就想到底是哪个地方出现了问题,这个问题困扰了我几天,百度找了无数答案,大部分都是说目录的权限有错误,需要修改权限,或者是selinux设置的问题,可是我运行的环境是windows,所以这些情况也被排除在外;有些说是需要设置Allowfromall,也没有效果。
 
  通过查看错误日志,发现有那么一行:
 
  AH01630:clientdeniedbyserverconfiguration:D:/www/
 
  但是我的Order指令设置都是正确的,这样我郁闷了一段时间,无意中发现了一篇文章描述Apache2.4与Apache2.2之间的一些指令的差异,刚好解决了我的问题,
 
  其中的一些指令已经无效,如:
 
  OrderDeny,Allow
 
  Denyfromall
 
  Allowfromal
 
  取而代之的是:
 
  Denyfromall
 
  变成
 
  Requirealldenied
 
  Allowfromall
 
  变成
 
  Requireallgranted
 
  于是我将虚拟机配置为:
 
  <VirtualHost*:80>
 
  DocumentRoot"D:/www/sphinx/api"
 
  ServerNamewww.mysphinx.com
 
  <Directory"D:/www/sphinx/api">
 
  DirectoryIndexindex.htmlindex.php
 
  Requireallgranted
 
  </Directory>
 
  </VirtualHost>
 
  发现还是提示403错误,只不过这次的错误日志的错误变成:
 
  AH01276:CannotservedirectoryD:/www/sphinx/api/:NomatchingDirectoryIndex(index.html,index.php)found,andserver-generateddirectoryindexforbiddenbyOptionsdirective
 
  这是因为里面的根目录里面没有index.html或者index.php,我们可以添加index.html文件或者将设置改成如下:
 
  <VirtualHost*:80>
 
  DocumentRoot"D:/www/sphinx/api"
 
  ServerNamewww.mysphinx.com
 
  <Directory"D:/www/sphinx/api">
 
  OptionsFollowSymLinksIndexes
 
  Requireallgranted
 
  </Directory>
 
  </VirtualHost>
 
  这样就是搞定了。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表