Php 如何在从上游读取响应标头时修复上游发送的标头过大?

Php 如何在从上游读取响应标头时修复上游发送的标头过大?,php,nginx,Php,Nginx,我的日志中有以下错误: 上游在从上游读取响应标头时发送了太大的标头 我试图补充 proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; 到我的nginx.conf http块,但不起作用 我还试图补充一点 fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; 到我的conf文件

我的日志中有以下错误:

上游在从上游读取响应标头时发送了太大的标头

我试图补充

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;
到我的nginx.conf http块,但不起作用

我还试图补充一点

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
到我的conf文件,但我找不到任何位置~.php${

所以我想知道我怎样才能克服这个错误? 添加


对于手工制作的php块,在/etc/nginx/nginx.conf:6中为我提供了nginx:[emerg]未知指令“location”,通常这个参数修复了“上游发送的头太大”的问题,您不需要为它们设置太大的值:),并为http或服务器块而不是位置设置它们

server {
...
    fastcgi_buffers  16 16k;
    fastcgi_buffer_size  32k;
}

此外,Firefox的FireHP有时会创建大标题,请尝试暂时禁用它。

上游发送的标题太大,而从上游读取响应标题
是nginx表达“我不喜欢我看到的东西”的通用方式

  • 上游服务器线程崩溃
  • 上游服务器发回了无效的头
  • 从STDERR返回的通知/警告破坏了它们的缓冲区,它和STDOUT都被关闭
  • 3:查看消息上方的错误日志,消息前面是否有记录的行?PHP消息:PHP注意:未定义索引: 循环我的日志文件中的示例代码段:

    2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
    PHP message: PHP Notice:  Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
    ... // 20 lines of same
    PHP message: PHP Notice:  Undefined index: Firstname in /srv/www/classes/data_convert.php on line 1090
    PHP message: PHP Notice:  Undefined index: Lastname in /srv/www/classes/data_convert.php on line 1090
    PHP message: PHP Notice:
    2015/11/23 10:30:02 [error] 32451#0: *580927 FastCGI sent in stderr: "ta_convert.php on line 1090
    PHP message: PHP Notice:  Undefined index: Firstname
    
    您可以在第3行(之前的20个错误)中看到缓冲区限制被命中、破坏,下一个线程在其上写入。Nginx随后关闭连接并将502返回给客户端

    2:记录每个请求发送的所有标题,检查它们并确保它们符合标准(nginx不允许任何超过24小时的内容删除/过期cookie,发送无效的内容长度,因为错误消息在内容计数之前已缓冲…)

    例子包括:

    <?php
    //expire cookie
    setcookie ( 'bookmark', '', strtotime('2012-01-01 00:00:00') );
    // nginx will refuse this header response, too far past to accept
    ....
    ?>
    
    
    
    这是:

    <?php
    header('Content-type: image/jpg');
    ?>
    
    <?php   //a space was injected into the output above this line
    header('Content-length: ' . filesize('image.jpg') );
    echo file_get_contents('image.jpg');
    // error! the response is now 1-byte longer than header!!
    ?>
    
    
    

    1:验证或制作脚本日志,以确保线程到达正确的端点,并且在完成之前没有退出。

    您可以发布整个配置吗?可能更相关的位在conf.d子目录中。类似的可能重复:在更改这些参数之前,您如何找到这些参数的实际值?我有两台机器相同的代码..一个有效一个无效..您的解决方案运行良好,但我想知道哪些值不起作用!感谢您提示禁用FireHP。这是我的错误原因。成功了,非常感谢。将Prestashop从Apache迁移到Nginx后发生的事。
    <?php
    header('Content-type: image/jpg');
    ?>
    
    <?php   //a space was injected into the output above this line
    header('Content-length: ' . filesize('image.jpg') );
    echo file_get_contents('image.jpg');
    // error! the response is now 1-byte longer than header!!
    ?>