为什么当目录在家里时禁止 apache 抛出? [英] Why apache throwing forbidden when directory is in home?

查看:33
本文介绍了为什么当目录在家里时禁止 apache 抛出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache 根本无法访问目录(forbidden 403 错误),无法确定原因?

Apache simply unable to access directory (forbidden 403 error), unable to identify the reason why ?

我已经创建了一个虚拟主机:

I have made a vhost as:

创建:/etc/apache2/sites-available/dev.testvhost.com.conf

created: /etc/apache2/sites-available/dev.testvhost.com.conf

<VirtualHost *:80>
    DocumentRoot /home/najam/projects/php/testvhost
    ServerName dev.testvhost.com
</VirtualHost>

在/etc/hosts 中添加服务器名

added servername in /etc/hosts

127.0.0.1       dev.testvhost.com

执行的命令:

sudo a2ensite dev.testvhost.com.conf

然后:

sudo service apache2 restart 

将浏览器指向 http://dev.testvhost.com 给出 403 禁止错误,而错误日志显示如下每次刷新.

pointing browser to http://dev.testvhost.com gives 403 forbidden error, while error log shows following on each refresh.

[2016 年 7 月 13 日星期三 16:19:42.277573] [authz_core:error] [pid 20067][客户端 127.0.0.1:58230] AH01630:客户端被服务器拒绝配置:/home/najam/projects/php/testvhost/

[Wed Jul 13 16:19:42.277573 2016] [authz_core:error] [pid 20067] [client 127.0.0.1:58230] AH01630: client denied by server configuration: /home/najam/projects/php/testvhost/

我非常确定导致错误的问题,因为testvhost"文件夹位于主目录/home/najam/projects/php/testvhost"中,当我将文件夹移动到/var/www/时,它开始工作(没有禁止错误)(在 dev.testvhost.com.conf 中相应修改 documentroot 路径后)

I am very sure about the issue causing error because "testvhost" folder is in home directory "/home/najam/projects/php/testvhost" and when I move the folder to /var/www/ it starts working (no forbidden error) (after modify documentroot path accordingly in dev.testvhost.com.conf)

推荐答案

尝试编辑您的 dev.testvhost.com.conf 为您希望访问的目录

Try editing your dev.testvhost.com.conf to add the Require all granted directive for the directory you want to be accessible

<VirtualHost *:80>
    DocumentRoot /home/najam/projects/php/testvhost
    ServerName dev.testvhost.com

    <Directory "/home/najam/projects/php/testvhost">
        Require all granted
    </Directory>
</VirtualHost>

该块由 Apache 的模块 mod_authz_core 控制.请参阅文档.

This block is controlled by Apache's module mod_authz_core. See the docs.

这篇关于为什么当目录在家里时禁止 apache 抛出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆