这是我在过去 2 年中对这个错误的理解:
upstream sent too big header while reading response header from upstream 是 nginx 表达“我不喜欢我所看到的”的通用方式
- 您的上游服务器线程崩溃了
- 上游服务器发回了无效的标头
- 从 STDERR 发回的通知/警告破坏了它们的缓冲区,并且它和 STDOUT 都已关闭
3:查看消息上方的错误日志,它是否在消息之前记录了行? PHP message: PHP Notice: Undefined index:
来自循环我的日志文件的示例 sn-p:
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:验证或制作脚本日志,以确保您的线程到达正确的终点并且在完成之前不会退出。