PHP-Nginx 服务的 FPM:504 网关超时 - nginx

PHP-FPM served by Nginx: 504 Gateway Time-out - nginx

我有一个 PHP Android 推送通知脚本。当我 运行 脚本时,我在浏览器中收到以下响应“504 Gateway Time-out nginx”。 在我的服务器上的一般日志概述中,我收到以下错误:

Error: 504, Message: GET /gcm_test.php HTTP/1.1, Source: nginx SSL access

在 proxy_error_log 我的服务器上出现以下错误:

2016/07/25 08:18:19 [error] 23882#0: *4375 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 12.34.567.891, server: website.com, request: "GET /gcm_test.php HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/website.com/php-fpm.sock", host: "www.website.com"

Android推送PHP脚本:

<?php
    // Replace with the real server API key from Google APIs
    $apiKey = "my apikey";

    // Replace with the real client registration IDs
    $registrationIDs = array("red id1", "reg id2");

    // Message to be sent
    $message = "Your message e.g. the title of post";

    // Set POST variables
    $url = 'https://gcm-http.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registrationIDs,
        'data' => array( "message" => $message ),
    );
    $headers = array(
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json'
    );

    // Open connection
    $ch = curl_init();

    // Set the URL, number of POST vars, POST data
    curl_setopt( $ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_POST, true);
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));

    // Execute post
    $result = curl_exec($ch);

    // Close connection
    curl_close($ch);
    // print the result if you really need to print else neglate this
    echo $result;
?>

如果我替换行“$result = curl_exec($ch);” "echo "脚本结束";"我没有收到任何错误,结果是 "End of script"。 所以看起来问题出在“$result = curl_exec($ch);”

我也尝试了以下方法,PLESK nginx 504 error: Gateway Timeout 没有成功。

在我的服务器上,我 运行ning PHP7.0.4 作为由 nginx

提供的 FPM 应用程序

有人有什么想法吗? 谢谢!

看来您需要在 nginx 配置中增加 fastcgi_read_timeout