403 Forbidden:将文档根文件夹移动到 iCloud 驱动器后 Apache 不工作

403 Forbidden : Apache not working after moving document root folder to iCloud drive

所以我使用的是 MacOS Catalina,我的 Apache 环境 运行 很好,直到我决定将我的文档根目录移动到 iCloud 驱动器,以保持备份。

之前我的文档根目录是:

/users/admin/www

现在是

/users/admin/Library/Mobile Documents/com~apple~CloudDocs/www

我相应地编辑了 httpd.conf :

DocumentRoot "/users/admin/Library/Mobile Documents/com~apple~CloudDocs/www"
<Directory "/users/admin/Library/Mobile Documents/com~apple~CloudDocs/www">
    Options FollowSymLinks Multiviews SymLinksIfOwnerMatch
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
</Directory>

<Directory "/users/admin/Library/Mobile Documents/com~apple~CloudDocs/www/myfolder">
    Options +FollowSymLinks +Multiviews +SymLinksIfOwnerMatch
    MultiviewsMatch Any
    AllowOverride All
    Allow from All
    Require all granted
</Directory>

重新启动 Apache,重新启动机器,但现在我可以访问 127.0.0.1,除了一个特定的文件夹(我们称之为 www/myfolder)。当我尝试访问 127.0.0.1/myfolder 时,出现以下错误:

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

检查 Apache 日志文件,这是我收到的错误:

[Thu Oct 24 14:00:24.830700 2019] [access_compat:error] [pid 61703] [client 127.0.0.1:57804] AH01797: client denied by server configuration: /users/admin/Library/Mobile Documents/com~apple~CloudDocs/www/myfolder/public_html/

我在这里错过了什么?请帮忙,我需要工作 :D

我首先看到的是您在目录块中使用的是 Apache 2.4 风格的语法,但是在您的错误日志中,抛出错误的模块是 access_compat。根据 Apache 文档:

The directives provided by mod_access_compat have been deprecated by mod_authz_host. Mixing old directives like Order, Allow or Deny with new ones like Require is technically possible but discouraged. This module was created to support configurations containing only old directives to facilitate the 2.4 upgrade

下一条线索是错误代码:AH01797。这是由 server configuration issue:

引起的

Client denied by server configuration

This error means that the access to the directory on the file system was denied by an Apache configuration.

我在这里假设您实际上使用的是 2.4,并且错误地启用了 access_compat

再次查看您的配置文件,找到正在加载 mod_access_compatLoadModule 指令,并将其注释掉。它可能在您的 httpd.conf 文件中,但是组织和配置 Apache 安装的方式多种多样,因此它可能在其他地方。如果你有一个 Debian 风格的安装,你需要删除符号 link /etc/apache2/mods_enabled/mod_access_compatGrep -R access_compat * 可能会有帮助。

编辑 2 个观察结果:

  1. 在第二个 directory 节中,您有
Allow from all
Require all granted

这是将旧指令语法与新指令语法混合在一起,也是多余的。再次禁用 access_compat,并在重新启动 Apache 之前删除 Allow from all 行。

  1. 我认为第二个 directory 节甚至没有必要。您可能可以删除整个块并重新启动服务器,这样就可以了。

首先尝试 (1),禁用 access_compat 并从 httpd.conf 文件中删除 Allow 指令,然后使用 apache2ctl -k graceful 重新启动 apache。如果这不起作用,请注释掉整个第二个 directory 节并重新启动。

我大约有 50% 的把握可以解决这个问题。如果没有,那么我真的需要查看您的整个 httpd.conf 文件才能进一步排除故障。