当前位置: 移动技术网 > 网络运营>服务器>Linux > apache documentroot指向htcdoc之外提示403错误的解决方法

apache documentroot指向htcdoc之外提示403错误的解决方法

2019年05月24日  | 移动技术网网络运营  | 我要评论
后来发现,原来又是apache没配置 好,是apache的mod_authz_host模块在起控制作用。 1.如果不启用vhosts 只需修改 httpd.conf 默认d
后来发现,原来又是apache没配置 好,是apache的mod_authz_host模块在起控制作用。
1.如果不启用vhosts
只需修改 httpd.conf
默认directory节如下,注意红色部分,表示目录/usr/local/apache/htdocs允许所有 主机访问
复制代码 代码如下:

<directory "/usr/local/apache/htdocs">
#
# possible values for the options directive are "none", "all",
# or any combination of:
# indexes includes followsymlinks symlinksifownermatch execcgi multiviews
#
# note that "multiviews" must be named *explicitly* --- "options all"
# doesn't give it to you.
#
# the options directive is both complicated and important. please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
#options indexes followsymlinks
#
# allowoverride controls what directives may be placed in .htaccess files.
# it can be "all", "none", or any combination of the keywords:
# options fileinfo authconfig limit
#
allowoverride none
#
# controls who can get stuff from this server.
#
order allow,deny
allow from all
</directory>

由于主目录被指到别的地方了,所以将蓝色部分/usr/local/apache/htdocs换成你新的主目录就ok了。
2.启用vhosts
启 用vhosts的话,你就可以不作上面的修改了,因为virtualhost可以单独配置这个节的属性,所以我们在virtualhost这个节里配置的 话就更方便了,下面的配置中,我把我的网站放在/var/vhosts/www.test.cn下。
复制代码 代码如下:

/usr/local/apache/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
<directory "/var/vhosts/www.test.cn" >
#deny from all
allow from all
</directory>
documentroot "/var/vhosts/www.test.cn"
servername www.test.cn
</virtualhost>

如果把deny from all的注释去掉,那么服务器就会拒绝所有访问(和我们刚开始把主目录移动到htdocs外而没做任何配置修改时一样,哈哈)
补充一点:
如果你是写个index.php放在目录下测试,可要注意了,记得加上默认主页index.php
directoryindex index.php

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网