# "upstream sent too big header while reading response header from upstream"?

**URL:** <https://www.ruby-forum.com/t/upstream-sent-too-big-header-while-reading-response-header-from-upstream/243999>\
**Category:** NGINX\
**Created:** [February 3, 2016, 2:25pm UTC](https://www.ruby-forum.com/t/upstream-sent-too-big-header-while-reading-response-header-from-upstream/243999 "2016-02-03T14:25:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [February 3, 2016, 2:25pm UTC](https://www.ruby-forum.com/t/upstream-sent-too-big-header-while-reading-response-header-from-upstream/243999/1 "2016-02-03T14:25:12Z")

</div>

Hi All.

I am currently trying to find the source of “upstream sent too big  
header  
while reading response header from upstream” in my logfiles because  
nginx  
as a consequence returns “502 Bad Gateway”.

Basically I used tcpdump to get the traffic and I compared two cases:

1. the communication is ok:

12167 07:03:51.466937 IP 10.10.3.7.80 \> 10.10.2.121.43817: Flags [P.],  
seq  
1779345520:1779348777, ack 1001934214, win 219, options [nop,nop,TS val  
2527240108 ecr 619023542], length 3257  
12168 E…7.@.@…  
12169  
12170 …  
12171  
12172 .y.P.)j…p;.M…  
12173 …$…HTTP/1.1 302 Found^M  
12174 Content-Length: 58^M  
12175 Content-Type: text/html; charset=utf-8^M  
12176 Date: Wed, 03 Feb 2016 12:03:51 GMT^M  
12177 Location: /^M  
12178 Set-Cookie: rfid-mgt-console=…  
12179 Set-Cookie: rfid-mgt-console.sig=xxx; path=/; expires=Wed, 03 Feb  
2016 13:03:51 GMT; httponly^M  
12180 Vary: Accept, Accept-Encoding^M  
12181 X-Cf-Requestid: yyy^M  
12182 X-Powered-By: Express^M  
12183 ^M  
12184

Moved Temporarily. Redirecting to /

In this case everything up to “Moved T…” is in one response from  
upstream  
(10.10.3.7).

1. nginx throws mentioned error to error.log and returns 502 code  
56874 06:31:45.307207 IP 10.10.3.7.80 \> 10.10.2.121.58073: Flags [P.],  
seq  
953075345:953079441, ack 3028520986, win 219, options [nop,nop,TS val  
2526758567 ecr 617097381], length 4096  
56875 E…4…@.@…  
56876  
56877 …  
56878  
56879 .y.P…8…h…  
56880 …F.$.(.HTTP/1.1 302 Found^M  
56881 Content-Length: 58^M  
56882 Content-Type: text/html; charset=utf-8^M  
56883 Date: Wed, 03 Feb 2016 11:31:45 GMT^M  
56884 Location: /^M  
56885 Set-Cookie: rfid-mgt-console=…  
56886 Set-Cookie: rfid-mgt-console.sig=xxx; path=/; expires=Wed, 03 Feb  
2016 12:31:45 GMT; httponly^M  
56887 Vary: Accept, Accept-Encoding^M  
56888 X-Cf-Requestid: yyy

56889 06:31:45.307213 IP 10.10.2.121.58073 \> 10.10.3.7.80: Flags [.],  
ack  
953079441, win 280, options [nop,nop,TS val 617097490 ecr 2526758567],  
length 0  
56890 E…4…@.@.zw  
56891  
56892 .y  
56893  
56894 …P…8…  
56895 $.)…F.

56896 06:31:45.307218 IP 10.10.3.7.80 \> 10.10.2.121.58073: Flags [P.],  
seq  
953079441:953079542, ack 3028520986, win 219, options [nop,nop,TS val  
2526758567 ecr 617097381], length 101  
56897 E…@.@…  
56898  
56899 …  
56900  
56901 .y.P…8…JU…  
56902 …F.$.(.503-564da79aecb5^M  
56903 X-Powered-By: Express^M  
56904 ^M  
56905

Moved Temporarily. Redirecting to /

In this case response from upstream (10.10.3.7) is much larger because  
of  
larger “Set-Cookie: rfid-mgt-console=…” returned and is divided into  
two  
parts. “upstream sent too big header while reading response header from  
upstream” is written to error.log.

For clarity I only pasted the part of the traffic which differs.

Initially in “http” section in nginx.conf:

…  
http {  
proxy\_max\_temp\_file\_size 0;

```
proxy_buffering off;

```

…

I tried to change it to:

…  
http {  
proxy\_max\_temp\_file\_size 0;

```
proxy_buffering on;

proxy_buffers 8 256k;

```

…

And I also added:

…  
proxy\_buffering on;

```
proxy_buffers 8 256k;

```

…

to my “server” sections. I performed a restart but the error did not  
change.

Can someone help me with this one?

BR,  
Rafal.

---

<div class="post-metadata">

**Author:** ![RafaSS\_Radecki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@RafaSS\_Radecki](https://www.ruby-forum.com/u/RafaSS_Radecki)\
**Post date:** [February 3, 2016, 2:42pm UTC](https://www.ruby-forum.com/t/upstream-sent-too-big-header-while-reading-response-header-from-upstream/243999/2 "2016-02-03T14:42:44Z")

</div>

You want proxy\_buffer\_size.

[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_buffer\_size](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size)

On Wed, Feb 3, 2016 at 2:24 PM, Rafał Radecki [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![RafaSS\_Radecki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@RafaSS\_Radecki](https://www.ruby-forum.com/u/RafaSS_Radecki)\
**Post date:** [February 3, 2016, 3:10pm UTC](https://www.ruby-forum.com/t/upstream-sent-too-big-header-while-reading-response-header-from-upstream/243999/3 "2016-02-03T15:10:46Z")

</div>

Thanks, solved 😉

BR,  
Rafal.

2016-02-03 14:42 GMT+01:00 Richard S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
