【问题标题】:Apache 403 error from accessing certain index.php or index.html despite having similar permissions for each访问某些 index.php 或 index.html 时出现 Apache 403 错误,尽管每个 index.php 或 index.html 具有相似的权限
【发布时间】:2026-01-28 15:20:10
【问题描述】:

我的 apache 服务器曾经可以正常工作,但它随机开始为几乎每个目录吐出 403 错误。两个目录仍在工作,如何让 /srv/www/htdocs 中的所有目录正常工作?

我查看了两个有效目录的权限,并将它们与其他未被访问的文件/文件夹进行了比较。两个工作目录是“BIBETIS”和“nextcloud”,而其他的都不起作用。

BIBETIS下的index.php文件归用户root,组www,权限为-rwxrwxr-x(我相信是755?)。该目录可以正常加载并按预期运行。

nextcloud 下的index.phpindex.html 文件由用户wwwrun 和组www 拥有。它的权限又是-rwxrwxr-x。这一切都按预期工作。

因此,基于此,我尝试了 sudo chown -R wwwrun:www /srv/www/htdocssudo chown -R wwwrun:www /srv/www/htdocs/*chmod -R 755 /srv/www/htdocs/ 和类似的变体。这并没有修复 apache 中的 403 错误。

我决定退后一步,专注于一个更简单的目录:“map”。该文件夹有一个 index.html 文件。我再次尝试如上所述更改权限,但似乎没有任何帮助。

apache 的错误日志如下:

[Fri May 10 01:39:35.665344 2019] [autoindex:error] [pid 2943] [client -:50203] AH01276: Cannot serve directory /srv/www/htdocs/map/: No matching DirectoryIndex (index.php4,index.php5,index.php) found, and server-generated directory index forbidden by Options directive
[Fri May 10 01:39:36.744342 2019] [autoindex:error] [pid 2943] [client -:50203] AH01276: Cannot serve directory /srv/www/htdocs/map/: No matching DirectoryIndex (index.php4,index.php5,index.php) found, and server-generated directory index forbidden by Options directive
[Fri May 10 01:39:42.323373 2019] [autoindex:error] [pid 2944] [client -:50204] AH01276: Cannot serve directory /srv/www/htdocs/map/: No matching DirectoryIndex (index.php4,index.php5,index.php) found, and server-generated directory index forbidden by Options directive
[Fri May 10 01:42:10.018496 2019] [autoindex:error] [pid 2038] [client -:50879] AH01276: Cannot serve directory /srv/www/htdocs/: No matching DirectoryIndex (index.php4,index.php5,index.php) found, and server-generated directory index forbidden by Options directive 

这让我相信它只是在搜索 index.php 文件?所以我在地图目录下设置了一个index.php,应用了正确的权限,它就可以工作了。如果是这样,为什么即使设置了正确的 user:group 和 755 权限,它也无法访问位于 htdocs 目录中的主 index.php

【问题讨论】:

    标签: linux apache permissions http-status-code-403


    【解决方案1】:

    你能告诉我们你的虚拟主机和你的 apache.conf/httpd.conf 的配置吗? 为了能够读取 index.html,您需要添加指令 DirectoryIndex index.html 否则您的 Web 服务器将不知道他需要读取它,它应该看起来像这样:

    DirectoryIndex index.html index.php4 index.php5 index.php
    

    错误信息显示清楚,与文件/文件夹权限无关!

    【讨论】:

      最近更新 更多