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

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

问题描述

我得到这样的错误:

  [error] 27544#0:* 47335682上游发送过大的标题, 
从上游的头,客户端:88.88.88.88,服务器:example..com,
请求:POST / tool / HTTP / 1.1,upstream:http://88.88.88.88:7080/ tool /,
host:example.com

可以从nginx conf文件中增加缓冲区大小,例如:上游发送过大的标头,同时从上游读取响应标头

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

位置
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

(为了将来参考,fastcgi_buffer_size和fastcgi_buffers的默认大小为4k或8k, / p>

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



我打算暂时增加缓冲区大小。然后我可以记录缓冲区太大时。是否可以找到对于上游太大的标题? apache_response_headers()和headers_list()没有给我所有的响应头。



更改proxy_buffer_size是否会导致性能问题?



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

解决方案

但是真正有所不同的是单个配置选项:

  http {
fastcgi_buffer_size 32k;
}

然而,这个建议可能不是你想要的。让我们详细了解为什么有助于解决问题:



fastcgi_buffer


语法:fastcgi_buffers number size;



默认值:fastcgi_buffers 8 4k | 8k;



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



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


fastcgi_buffer_size


语法: fastcgi_buffer_size size;



默认值:fastcgi_buffer_size 4k | 8k;



上下文:http,server,location



设置用于读取从FastCGI服务器接收的
响应的第一部分的缓冲区大小。这部分通常包含
一个小的响应头。默认情况下,缓冲区大小等于一个
内存页。这是4K或8K,取决于一个平台。


因此,只有 fastcgi_buffer_size 因为响应头不适合4KB缓冲区。大多数时间它发生由于大的cookie大小。因此,强烈建议保留设置,但减少cookie大小,并且只有最小量的数据存储在那里像user_id,session_id,所以一般想法cookie存储是针对非敏感的ID集。某些浏览器不会处理大型Cookie。



因此解决方案是:

  1。减小Cookie大小

2.返回原始设置

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

如果遇到减小Cookie大小的问题,请关闭特定位置的缓冲: / p>

 位置/请求{
fastcgi_buffering off;
}


I get error like this:

[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"

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;

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

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

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.

Does changing proxy_buffer_size makes a performance problem ?

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

解决方案

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:

Syntax: fastcgi_buffers number size;

Default: fastcgi_buffers 8 4k|8k;

Context: http, server, location

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:

Syntax: fastcgi_buffer_size size;

Default: fastcgi_buffer_size 4k|8k;

Context: http, server, location

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.

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.

So the solution would be:

1. Reduce cookie size

2. Get back to original settings

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

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

location /request {
  fastcgi_buffering off;
}

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

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