【问题标题】:Upstream prematurely closed FastCGI stdout while reading response header from upstream上游从上游读取响应标头时过早关闭 FastCGI 标准输出
【发布时间】:2016-05-26 10:00:21
【问题描述】:

我突然收到 502 Bad gateway 错误,我不明白为什么会出现这个错误。此外,此错误仅针对 1 个单页出现!!...

我的 Nginx 日志中的确切错误是:

 Upstream prematurely closed FastCGI stdout while reading response header from upstream [..] upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"

我试过了:

  • 服务 nginx 重启:没有任何变化
  • 服务 php5-fpm 重启:没有任何变化
  • 重启服务器:NOTHING CHANGE
  • 即使重启 mysql 服务:NOTHING CHANGE

我的/var/log/upstart/php5-fpm.log(只有很多通知):

Terminating...
exiting, bye-bye!
fpm is running, pid 9887
ready to handle connections
systemd monitor interval set to 10000ms

这让我发疯了,你知道吗?

【问题讨论】:

  • 有什么解决办法吗?它发生在我身上,并没有改变任何东西。

标签: php html mysql logging nginx


【解决方案1】:

奇怪的是,在追查了一个神秘的 502 Bad Gateway 错误之后,这对我有用:

  • 像这样在php-fpm ini 中更改error_reporting 设置:

    error_reporting = ~E_ALL

  • 然后重启php-fpmnginx

在尝试了上面建议的 nginx 设置无济于事后,这对我有用。我对此没有经过验证的解释,但似乎过多的错误报告可能会使 php-fpm 进程过载。

【讨论】:

    【解决方案2】:

    我对服务器 nginx 配置做了以下操作:

       client_body_timeout 1200;
       client_header_timeout 600;
    

    并将 zend_extension 添加到 php fpm php.ini:

    zend_extension = xdebug.so
    

    【讨论】:

      【解决方案3】:

      尝试在源文件中使用include <fcgi_stdio.h>。 这个错误刚刚发生在我身上,然后我在我的c文件中添加include <fcgi_stdio.h>,这是我的代码。

      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <unistd.h>
      #include <fcgi_config.h>
      #include <fcgi_stdio.h>
      
      int main()
      {
          int count = 0;
          while(FCGI_Accept() >= 0)
          {
              printf("content-type:text/html\r\n");
              printf("\r\n");
              printf("<title>Fast CGI Hello</title>");
              printf("<h1>fast CGI hello</h1>");
      
              printf("Request number %d running on host<i>%s</i>\n",++count,getenv("SERVER_NAME"));
          }
      
          return 0;
      }
      

      【讨论】:

        【解决方案4】:

        我仅在正文中有 12 项的一种类型的请求中出现错误。可能与体型有关,但当它更多(13 件或更多)或更少(11 件或更少)时,它会起作用。

        上游在从上游读取响应标头时过早关闭 FastCGI 标准输出

        2021/12/24 07:14:44 [error] 9#9: *49 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: 172.21.0.1, server: , request: "PUT /v1/MY_PAGE/a976d2e5-afc0-4f6d-8d05-17af7dc73f46 HTTP/1.1", upstream: "fastcgi://172.21.0.3:9000", host: "localhost"
        

        我在 Nginx 和 PHP-FPM 中使用了 Docker 容器。

        Nginx 返回 502 Bad Gateway

        使用了PHP-FPM XDebug,出现了错误。

        当我打开调试时出现错误,当我关闭调试时返回错误。

        解决方案

        为了解决这个错误,我禁用了 XDebug。当我删除 XDebug 时它也可以工作。

        解决错误的选项(其中之一):

        • 禁用 XDebug(其中之一):
        • 从您的 PHP 服务器中删除 XDebug 并重新启动 PHP-FPM(其中之一):
          • 通过 PECL 删除(与 Docker 一起使用):pecl uninstall xdebug
          • 通过 Ubuntu APT 删除:sudo apt-get purge php-xdebug

        重新启动您的 PHP-FPM 或您的服务/服务器。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-04-21
          • 2018-09-21
          • 2019-01-17
          • 2018-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-08-15
          相关资源
          最近更新 更多