无法访问localhost - 403禁止访问

时间:2012-05-27 17:45:17

标签: php apache localhost lamp http-status-code-403

我可以访问localhost的某些区域但无法访问其他区域 例如,

  • 我可以访问localhost/index.phplocalhost/somefolder/

  • 但不是localhost/somefolder/anotherfolder

我也无法include来自anotherfolder内的任何文件,因为它显示failed to open stream: No such file or directory

我有chmod -R 755 www但仍然无法访问子目录

可能是什么原因?

2 个答案:

答案 0 :(得分:3)

检查是否在该机器上运行SELinux。然后在你可以查看的目录和你不能查看的目录上执行ls -alZ。如果启用了SELinux,则无法查看的目录的安全组未设置为http安全组。我认为它应该是system_u:object_r:httpd_sys_content_t的效果。

检查/etc/selinux/config中系统上是否启用了SELinux。如果是,请转到您遇到问题的目录,然后键入:chcon -Rv --type=httpd_sys_content_t <directory name>。这将把httpd内容安全标志添加到该目录及其下的所有内容,允许apache访问它。

答案 1 :(得分:2)

如果您的文件夹中没有“index.html”(或index.php),则在未将您的目录公开的情况下无法访问它们。默认情况下应该禁用它,但是对于包含问题,我需要一些代码和目录树。