【问题标题】:404 when file is on server文件在服务器上时出现 404
【发布时间】:2014-08-19 15:55:59
【问题描述】:

尝试使用浏览器访问a simple PHP script 我可以找到它。但是,尝试通过curlget_headers 访问它会得到 404 结果。比如

$url = 'http://dardesarchat.ir/findme.php';
print_r(get_headers($url, 1));

给予

Array
(
    [0] => HTTP/1.1 404 Not Found
    [Date] => Sat, 28 Jun 2014 19:38:34 GMT
    [Server] => Apache/2
    [Accept-Ranges] => bytes
    [Vary] => Accept-Encoding,User-Agent
    [Connection] => close
    [Content-Type] => text/html
)

这与 dns 无关,因为尝试 get_headershttp://dardesarchat.ir/index.html 会返回 [0] => HTTP/1.1 200 OK,只有 PHP 文件找不到

这也与 PHP 无关(如果某些 cookie 丢失,则故意返回 404 等)。 findme.php 中的代码是这样的:

<?php
die('I sure am here :P');
?>

最后,主机上没有htaccess文件。这怎么可能?

【问题讨论】:

  • 我尝试从这里卷曲,它可以工作。您是否正在尝试从托管服务器本身 curl / get_headers?有时 Apache 未配置为监听 localhost...
  • @Khôi,这发生在远程安装程序上,我在主服务器上有主脚本,在这个服务器上有从属脚本。远程安装程序已经成功安装了 30 多个具有这种精确排列的应用程序实例,尽管它突然为这个特定域给出了这个奇怪的结果。
  • 很难说,index.html 真的是您所期待的吗? dardesarchat.ir 是否解析到从机上的正确服务器/IP?我想它可能是你到达那里的任何 index.html。
  • @Khôi,好点子!我将添加一个findme.html 来检查是否是这种情况,或者它是否与文件类型有关。
  • @Khôi,你是对的! http://dardesarchat.ir/findme.html 也返回 404!那么,应该是 DNS 相关的,我们可以说 DNS 记录在某些子网中已经更新,而在其他子网中没有?

标签: php curl http-status-code-404


【解决方案1】:

排除一般网络问题:

最常见的问题总是 DNS 问题。

  1. 检查您的客户端计算机是否可以正确解析服务器(来自客户端计算机的nslookupping 应该显示正确的 IP)。还要注意 IPv4 和 IPv6,因为 Apache 服务器通常只侦听 IPv4 连接。

  2. 检查/etc/hosts(或Windows 上的\system32\drivers\etc\hosts)中是否有奇怪的配置。

  3. 如果该服务器恰好安装了 Web 服务器,curl / wget index.html 可能会为您提供任何 index.html

  4. 检查您的客户端计算机中配置了哪些 DNS 服务器 (/etc/resolv.conf)

其他可能的错误来源:

  • 客户端计算机是否在(透明)代理后面?
  • 客户端计算机是否在一个奇怪的网络中,网关上有更奇怪的路由表?

【讨论】:

    【解决方案2】:

    当我使用与您完全相同的代码时,我收到了 HTTP 200 响应。

    $url = 'http://dardesarchat.ir/findme.php';
    print_r(get_headers($url, 1));
    

    给我:

    [0] => HTTP/1.1 200 OK
    

    我没有发现任何问题。

    【讨论】:

    • 我仍然得到 404,并且想不出发生这种情况的任何原因。
    猜你喜欢
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2020-03-17
    • 1970-01-01
    相关资源
    最近更新 更多