Nginx 上游在从上游读取响应头时发送了太大的头 [英] Nginx upstream sent too big header while reading response header from upstream

查看:17
本文介绍了Nginx 上游在从上游读取响应头时发送了太大的头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这样的错误:

[error] 27544#0: *47335682 upstream sent too big header while reading response 
 header from upstream, client: 88.88.88.88, server: example..com,
 request: "POST /tool/ HTTP/1.1", upstream: "http://88.88.88.88:7080/tool/",
 host: "example.com"

关于这个问题,可以像这样从 nginx conf 文件中增加缓冲区大小:上游从上游读取响应头时发送的头太大

Regarding to this question, it is possible to increase buffer size from nginx conf file like this: upstream sent too big header while reading response header from upstream

http {
  proxy_buffer_size   128k;
  proxy_buffers   4 256k;
  proxy_busy_buffers_size   256k;
}

location
      fastcgi_buffers 16 16k; 
      fastcgi_buffer_size 32k;

(供将来参考,fastcgi_buffer_size 和 fastcgi_buffers 的默认大小为 4k 或 8k,取决于平台)

(For future reference, default size for fastcgi_buffer_size and fastcgi_buffers is 4k or 8k, regarding to platform)

此文本出现在用户浏览器中:Nginx 502 Bad Gateway

This text appears in user's browser: Nginx 502 Bad Gateway

我打算暂时增加缓冲区大小.然后我可以在缓冲区太大时记录.是否可以找出对于上游来说太大的标头?apache_response_headers() 和 headers_list() 没有给我所有的响应头.它只给了我过期、缓存控制和杂注标头.

I'm planning to temporarily increase buffer size. Then I can log when the buffers are too big. Is it possible to find out headers which is too big for upstream ? apache_response_headers() and headers_list() didn't give me all response headers. It only gave me expires, cache-control and pragma headers.

更改 proxy_buffer_size 会导致性能问题吗?

Does changing proxy_buffer_size makes a performance problem ?

(nginx版本:nginx/1.6.0,php 5.4.42,xcache 3.2)

(nginx version: nginx/1.6.0, php 5.4.42, xcache 3.2)

推荐答案

你可以很容易地找到关于 SO 的答案,但真正重要的是单一配置选项:

You can easily find an answer on SO, but what really makes a difference is the single configuration option:

http {
  fastcgi_buffer_size 32k;
}

尽管如此,此建议可能不是您想要的.让我们看看为什么这有助于解决问题:

Nevertheless this recommendation is probably not what you want. Let's see through details why that helps to solve problem:

fastcgi_buffer:

语法:fastcgi_buffers 数字大小;

Syntax: fastcgi_buffers number size;

默认:fastcgi_buffers 8 4k|8k;

Default: fastcgi_buffers 8 4k|8k;

上下文:http、服务器、位置

Context: http, server, location

设置用于读取响应的缓冲区的数量和大小从 FastCGI 服务器,用于单个连接.默认情况下,缓冲区大小等于一内存页.这是4K或8K,取决于平台.

Sets the number and size of the buffers used for reading a response from the FastCGI server, for a single connection. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform.

fastcgi_buffer_size:

语法:fastcgi_buffer_size 大小;

Syntax: fastcgi_buffer_size size;

默认:fastcgi_buffer_size 4k|8k;

Default: fastcgi_buffer_size 4k|8k;

上下文:http、服务器、位置

Context: http, server, location

设置用于读取第一部分的缓冲区大小从 FastCGI 服务器收到的响应.这部分通常包含一个小的响应头.默认情况下,缓冲区大小等于 1内存页.这是 4K 或 8K,具体取决于平台.它可以但是,要做得更小.

Sets the size of the buffer used for reading the first part of the response received from the FastCGI server. This part usually contains a small response header. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform. It can be made smaller, however.

所以只有 fastcgi_buffer_size 会有所不同,因为响应标头不适合 4KB 缓冲区.大多数情况下,它是由于 cookie 的大小而发生的.因此,强烈建议保持设置不变,但减少 cookie 大小,并且只存储最少量的数据,如 user_id、session_id,因此一般的想法 cookie 存储是用于不敏感的 ID 集.有些浏览器不能很好地处理大 cookie.

So there is only fastcgi_buffer_size makes a difference because response header doesn't fit into the 4KB buffer. Most of time it happens due to large cookie size. So it's strongly recommended to leave settings as is but reduce cookie size instead and have only minimal amount of data stored there like user_id, session_id, so the general idea cookie storage is for non-sensitive set of IDs. Some browsers don't treat large cookies well.

所以解决办法是:

1. Reduce cookie size

2. Get back to original settings

http {
  fastcgi_buffers 8 4k;
  fastcgi_buffer_size 4k;
}

如果在减小 cookie 大小时遇到​​困难,请关闭特定位置的缓冲:

In case of difficulties with reduce cookie size turn off buffering for certain location:

location /request {
  fastcgi_buffering off;
}

这篇关于Nginx 上游在从上游读取响应头时发送了太大的头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆