【问题标题】:Apache alias throws "You don't have permission to access" errorApache 别名抛出“您没有访问权限”错误
【发布时间】:2018-04-01 00:02:47
【问题描述】:

发帖前,我看了:

You don't have permission to access / on this server

Application of DirectoryIndex to an Alias in Apache

据我了解,Alias 指令允许将文档存储在本地文件系统中,而不是在 DocumentRoot 下。

这就是我在这里所做的。我在 C:\Users\dogzilla\PhpstormProjects\Webpage 中有一个 hello.php 文件

那不是我的 docroot... C:\Apache\latest\www 是。

当我运行项目时,从IDE发送到浏览器的URL是

localhost:8080/网页/hello.php

这会导致 404 错误。

但我不想在 IDE 设置上多费神,所以我将它添加到我的 httpd.conf 中。我只抓取了“网页”,因为这就是显示 404 错误时 URL 中的全部内容。

别名 /Webpage C:/Users/dogzilla/PhpstormProjects/Webpage

当我重新运行我的项目时,404 消失了,但出现了 403 错误。

所以,在阅读上面的这两个链接时,我也将其添加到 httpd.conf 中:

<Directory "C:/Users/dogzilla/PhpstormProjects/Webpage">
  Order allow,deny
  Allow from all
</Directory>

(是的,一旦运行,我会加强安全性)

但我仍然收到 403 错误。

我做错了什么?我试过RTFM。显然我还是做错了什么。

【问题讨论】:

  • @CBroe 为什么我“必须”这样做? Apache 别名的设置正是我首先在这里发帖的原因。
  • 您应该将Options Indexes 添加到您的目录权限中,以防您的服务器找不到默认文件(index.html、index.php......),服务器会返回您的目录.如果未实现“选项索引”,则服务器返回 403 Forbiden - 您可以在下面看到我的完整答案

标签: apache


【解决方案1】:

如果您要为 DocumentRoot外部目录创建别名,您可能需要明确允许访问 strong> 到目标目录

Alias "/image" "/ftp/pub/image"
<Directory "/ftp/pub/image">
    Require all granted
    Options Indexes
</Directory>

如果未设置Options Indexes,并且未找到默认文件,则服务器返回403 status code,并且不会显示您的目录。

服务器会尝试打开的默认文件位于httdd.conf

<IfModule dir_module>
        DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                       default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                       home.php home.pl home.cgi home.asp home.shtml home.html home.htm
    </IfModule>

【讨论】:

    【解决方案2】:

    我想我找到了答案...我使用的是 2.2 conf 命令而不是 2.4。这些链接带来了光明。随着 httpd.conf 在 2.2 和 2.4 之间的变化,我猜故事的寓意是要注意细节:

    https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration

    Forbidden You don't have permission to access / on this server

    【讨论】:

    • 对于其他任何人来说,在我的情况下,我的 Apache 指令是正确的,但是有一个 .htaccess 文件阻止访问。
    猜你喜欢
    • 2013-01-03
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多