【问题标题】:Nginx IPv6 Configuration IssueNginx IPv6 配置问题
【发布时间】:2012-09-19 07:15:16
【问题描述】:

我的网络服务器(使用 nginx 托管 facebook 应用程序)开始收到错误提示

*907768 FastCGI sent in stderr: "Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server" while reading response header from upstream, client:...

此错误的原因可能是什么?我并不总是明白这一点。

【问题讨论】:

    标签: php nginx fastcgi


    【解决方案1】:

    错误来自 php 代码,更具体地说 - facebook sdk。当 facebook 代码尝试连接到 ipv6 地址但无法连接到网络时会抛出此错误,很可能是由于系统中启用了 ipv6 但没有 ipv6 连接(引自base_facebook.php):

    // With dual stacked DNS responses, it's possible for a server to
    // have IPv6 enabled but not have IPv6 connectivity.  If this is
    // the case, curl will try IPv4 first and if that fails, then it will
    // fall back to IPv6 and the error EHOSTUNREACH is returned by the
    // operating system.
    if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
        $matches = array();
        $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
        if (preg_match($regex, curl_error($ch), $matches)) {
          if (strlen(@inet_pton($matches[1])) === 16) {
            self::errorLog('Invalid IPv6 configuration on server, '.
                           'Please disable or get native IPv6 on your server.');
            self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
            $result = curl_exec($ch);
          }
        }
    }
    

    处理此问题的正确方法是在系统中禁用 ipv6 或获取一些 ipv6 连接。或者,应该可以通过在您的代码中要求 facebook 代码始终使用 ipv4 来抑制错误:

    Facebook::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
    

    【讨论】:

    • 谢谢你的回答,你能告诉我在base-facebook.php中我可以把那个sn-p放在哪里吗?
    • sn-p 用于你的代码,放在require '/path/to/facebook.php'之后。我根本不建议编辑 base_facebook.php。这样您就可以安全地从 facebook 更新 base_facebook.php。如果您可以编辑 facebook sdk,则将选项直接放入 $CURL_OPTS 数组中。
    猜你喜欢
    • 2014-06-03
    • 2012-03-17
    • 2012-08-17
    • 1970-01-01
    • 2020-03-04
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多