当 PHP 告诉 Apache 404 时,Apache 会重置连接

发布于 2024-12-29 07:58:54 字数 1035 浏览 3 评论 0原文

鉴于通过 Apache 2.2.9 提供以下 PHP 5.1.6 代码:

<?php
header("HTTP/1.1 404 Not Found");

当我(使用任何浏览器)浏览到此文件时,我收到一条“连接重置”消息。 (Firefox 说“页面加载时与服务器的连接已重置。”,Chrome 说“与 staging.neopets.com 的连接已中断。”标头调用后是否有任何正文都没有区别。

httpd.conf 具有强制所有请求通过前端控制器脚本运行的重写规则,这就是前端控制器多年来尝试路由请求的方式,如果不能,它会设置404 响应代码, 时就崩溃

显示一些错误副本,然后退出。无论出于什么原因,今天它决定在error.log 显示任何请求 。被用作 404s:

192.168.0.2 - - [26/Jan/2012:12:03:11 -0800] "GET /text.php HTTP/1.1" 404 20 "-" "Mozilla/5.0 (X11; Linux i686; rv:8.0.1) Gecko/20100101 Firefox/8.0.1"

Apache 配置已经有几个月没有被触及了。所有其他标头响应都正常工作(401、403、200、302 等),其他一切都完全正常,但由于某种原因,如果我让 PHP 做出上面调用,它重置了连接。

我什至用 Wireshark 观察它,它在发送请求后发回一大堆 RST,ACK 数据包。

执行 wget localhost/test.php (从有问题的机器)工作正常,但执行 wget badhost/test.php (从另一台机器)显示连接重置错误,如下所示出色地。也许 Apache 正在对 404 的远程请求进行某种反向 IP 查找并崩溃?

编辑:经过进一步调查,发现这是一些网络问题,托管设施和我们办公室之间的 404 错误因连接重置而被终止。所以,关闭,因为这不是这里任何人都可以回答的问题;-) 谢谢!

Given the following PHP 5.1.6 code being served through Apache 2.2.9:

<?php
header("HTTP/1.1 404 Not Found");

When I browse to this file (with any browser) I get a "connection reset" message. (Firefox says "The connection to the server was reset while the page was loading.", and Chrome says "The connection to staging.neopets.com was interrupted." It makes no difference whether there's any body after the header call.

httpd.conf has rewrite rules that force all requests to run through a front controller script. This is how it's worked for years. The front controller tries to route the request, and if it can't, it sets the response code to 404, shows some error copy, and exits. For whatever reason, today it decided to lose its mind and blow up whenever a

error.log shows nothing. access.log shows the requests being served as 404s:

192.168.0.2 - - [26/Jan/2012:12:03:11 -0800] "GET /text.php HTTP/1.1" 404 20 "-" "Mozilla/5.0 (X11; Linux i686; rv:8.0.1) Gecko/20100101 Firefox/8.0.1"

The Apache config has not been touched in months. All other header responses work properly (401, 403, 200, 302, etc.), everything else is totally normal, but for some reason if I have PHP make the call above, it resets the connection.

I even watched it with Wireshark and it sends back a whole bunch of RST,ACK packets after the request is sent.

Doing wget localhost/test.php (from the machine in question) works fine, but doing wget badhost/test.php (from another machine) shows a connection reset error as well. Maybe Apache is doing some kind of reverse IP lookup on remote requests for 404s and melting down?

EDIT: After further investigation, turns out it's some network problem where 404s between the hosting facility and our office are killed with a connection reset. So, closing because it's not something that anyone here can answer ;-) Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花似海 2025-01-05 07:58:54

从 PHP 脚本发送的标头并不是让 Apache 显示其 404 页面的原因。当 Apache 找不到所请求的文件时,它会显示 404 页面(并发送 404 标头)。由于这里的情况并非如此(因为 test.php 已找到并执行),因此 404 标头没有任何意义。这可能就是让您的浏览器感到困惑的原因。

如果您将其称为某些应用程序错误处理或其他内容的一部分,那么您应该做的是将用户重定向到应用程序的自定义“找不到文件”页面。

That header that you send from your PHP script is not what makes Apache display its 404 page. Apache displays a 404 page (and sends a 404 Header) when it can't find the requested file. Since this is not the case here (because test.php is found and executed), that 404 header has no sense. That is probably what got your browser(s) confused.

If you call this as part of some application error handling or something, what you should do instead is redirect the user to the application's custom "File not found" page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文