【问题标题】:ErrorDocument in httpd.conf not workinghttpd.conf 中的 ErrorDocument 不起作用
【发布时间】:2014-12-29 20:24:00
【问题描述】:

我想为 403 使用自定义错误文件,但 apache 似乎忽略了指令 ErrorDocument,只是给了我默认的错误文件。这是我httpd.conf的开头

ServerRoot "C:/xampp/apache"

Listen 80

ErrorDocument 403 "/403.html" 
ErrorDocument 404 "/403.html"

我刚刚添加了404 以查看它是否有效,但它没有。文件403.html存在于C:\xampp\apache\403.html

我尝试在配置文件中将ErrorDocument 指令进一步向下移动,其中描述ErrorDocument 指令的cmets 开始但结果相同。

我正在测试的文件夹中的任何.htaccess 文件中都没有ErrorDocument 指令。

你能告诉我为什么 apache 不理我吗?

编辑

为了确保我会提到我测试这个的方式。我在C:\xampp\htdocs 中有一个.htaccess 文件,其中包含以下内容

Order deny,allow
Allow from 127.0.0.1
Allow from ::1
Deny from all

其目的是拒绝访问所有未明确允许的子文件夹和文件,然后我只是向我的公共 IP 发送请求以拒绝访问。

【问题讨论】:

标签: windows apache xampp errordocument


【解决方案1】:

如果出现任何错误,首先要查看的是 apache 安装的 logs/error.log 和 logs/access.log 日志文件。

正如http://httpd.apache.org/docs/2.2/mod/core.html#errordocument 的文档所述,此指令与您当前主机配置的DocumentRoot 相关。 您没有使用默认的 Apache HTTPD,而是使用预配置的 Apachefriends XAMPP,它具有一些特殊功能,例如XAMPP 附带的标准httpd.conf 通过

引用ErrorDocuments
# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf

在默认的httpd.conf 中,您的DocumentRoot 是C:\apache\htdocs,因此在您的httpd.conf 中进行上述更改(即ErrorDocument 403 "/403.html")后,您必须将这些文件放入C:\xampp\htdocs\403.html。

顺便说一句,通过将Include conf/my-custom.conf 添加到httpd.conf 并在其中添加您的配置来分离您的自定义配置通常是一个好主意。

【讨论】:

  • 我将文件移动到C:\xampp\htdocs\403.html 并重新启动了 apache,以防万一,但我仍然得到默认的错误文档。感谢您对单独配置文件的建议,这是个好建议!
  • 移动文件后,您是否确认127.0.0.1/403.html 返回了您的HTML 文件?下一步是在.htaccess 文件中设置ErrorDocument 指令。如果这工作正常,问题是您在 httpd.conf 中修改的 ErrorDocument 指令不适用于 htdocs 文件夹。
  • 一个指令被另一个指令覆盖是很常见的,例如在更具体的范围或加载阶段后期的位置。这就是为什么我建议有一个单独的配置文件,例如使用 <Virtualhost> 或 <Directory> 指令。这就是您现在通常将获得的配置放入 .htaccess 文件的位置。将ErrorDocument 指令放入.htacess 会产生什么结果?
猜你喜欢
  • 2013-03-03
  • 2013-05-10
  • 2017-12-27
  • 1970-01-01
  • 2013-07-18
  • 2017-11-27
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
相关资源
最近更新 更多