配置好apache服务器后,访问虚拟主机出现403错误,即没有权限访问。
在网上搜索了解决方法,不过我对这个方法表示一些怀疑,先摘抄原文如下:
请教出现这个问题的原因是什么呢?如何解决?
这可能是由于你更改了你的DocumentRoot,如 D:/test 。用记事本打开Apache的httpd.conf。而更改了这个默认值后,下面还有一个值是要随着更改的。就在它下面不远的地方,有这样一段:
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory “D:/test”>
中括号里的内容就是你更改的新值。这样就不会出现403错误了。<Directory “/var/www/html1/”>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>修改了Apache的httpd.conf,一定要重启Apache服务器。否则你测试仍然会失败。而有的朋友在做了上面的一步时,仍然会有同样的错误提示。可能是你的Apache版本的问题。
你仔细检查一遍配置文件httpd.conf,找到这么一段:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
deny from all
Satisfy all
</Directory>把deny from all中的deny改成了allow,保存后重启apache即可。Apache2.2及其以后的版本不用修改这一项。Apache2.0及其以前的版本就可能要修改。
在这里我的确是修改了DocumentRoot,并且把创建的项写在单独的配置文件中,储存在自己的应用目录,然后在主Apache的httpd.conf文件中include自己创建的配置文件。
根据上面文章,首先在主Apache的httpd.conf文件中找到这段代码,注释里没有提到自己定义DocumentRoot的话这里必须也要修改,这里说的只是By default的时候会访问这个目录。应该说如果没有自定义的话,这将是系统的默认DocumentRoot,仅此而已。
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”
然后找到默认的Directory项
显然,注释里也说明了这是对默认”default”的一组设置,这组设置是比较严格的。
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the “default” to be a very restrictive set of
# features.
#
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
所以,我觉得不需要修改主httpd.conf,在自定义的httpd.conf里修改就行了,我在项里加了
allow from all项,就能够正常访问自定义的virtualHost了。