# How to avoid "too big header" issue?

**URL:** <https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067>\
**Category:** NGINX\
**Created:** [April 21, 2011, 1:02pm UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067 "2011-04-21T13:02:49Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 21, 2011, 1:02pm UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/1 "2011-04-21T13:02:49Z")

</div>

There’s hundreds of “setcookie(‘xxx’,‘yyy’)” lines in one of my php  
page,the size of these cookies is about 2-10KB,so nginx always throw a  
typical “502 bad gateway”.

my solutionA is: add this to nginx.conf:

client\_header\_buffer\_size 8m;  
large\_client\_header\_buffers 8 8m;  
fastcgi\_buffer\_size 8m;  
fastcgi\_buffers 8 8m;

result:no effect. I tried increasing the size from 8m to 128m,but it  
still give me a 502 errror.

and solution B:

fastcgi\_ignore\_headers Set-Cookie;

result:no effect. In error log,there’s still a large amount of  
‘Set-Cookie’ header info:

2011/04/21 18:28:10 [debug] 66257#0: \*2 http fastcgi header:  
“Set-Cookie: xxx=yyy; expires=Wed, 21-Apr-2010 10:28:09 GMT”  
…  
…  
2011/04/21 18:28:10 [debug] 66257#0: \*2 http fastcgi parser: -2  
2011/04/21 18:28:10 [debug] 66257#0: \*2 upstream split a header line in  
FastCGI records  
2011/04/21 18:28:10 [error] 66257#0: \*2 upstream sent too big header  
while reading response header from upstream…

Posted at Nginx Forum:

> **[How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,192785#msg-192785)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [April 22, 2011, 8:35am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/2 "2011-04-22T08:35:12Z")

</div>

On Thu, Apr 21, 2011 at 07:02:27AM -0400, stalkercn wrote:

> 2011/04/21 18:28:10 [debug] 66257#0: \*2 http fastcgi header:  
> “Set-Cookie: xxx=yyy; expires=Wed, 21-Apr-2010 10:28:09 GMT”  
> …  
> …  
> 2011/04/21 18:28:10 [debug] 66257#0: \*2 http fastcgi parser: -2  
> 2011/04/21 18:28:10 [debug] 66257#0: \*2 upstream split a header line in  
> FastCGI records  
> 2011/04/21 18:28:10 [error] 66257#0: \*2 upstream sent too big header  
> while reading response header from upstream…

Which nginx version do you use ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [April 27, 2011, 2:46am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/3 "2011-04-27T02:46:44Z")

</div>

The version is 0.8.54. thx.

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,193941#msg-193941)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [April 29, 2011, 5:15am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/4 "2011-04-29T05:15:49Z")

</div>

fastcgi\_buffer doesn’t work,I tried proxy method,it seems working for  
me,but slowly:

nginx.log  
2011/04/29 11:02:57 [debug] 33323#0: kevent timer: 61402, changes: 0  
2011/04/29 11:03:02 [debug] 33323#0: kevent events: 1

When nginx handle one file,the time between two lines is 5 secs,why  
here?

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,194392#msg-194392)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 4, 2011, 5:11am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/5 "2011-05-04T05:11:17Z")

</div>

anyone can help me?

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195465#msg-195465)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 5, 2011, 4:50am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/6 "2011-05-05T04:50:27Z")

</div>

nginx version: nginx/0.8.54  
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt=‘-I  
/usr/local/include’ --with-ld-opt=‘-L /usr/local/lib’  
–conf-path=/usr/local/etc/nginx/nginx.conf  
–sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid  
–error-log-path=/var/log/nginx-error.log --user=www --group=www  
–with-debug  
–http-client-body-temp-path=/var/tmp/nginx/client\_body\_temp  
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi\_temp  
–http-proxy-temp-path=/var/tmp/nginx/proxy\_temp  
–http-scgi-temp-path=/var/tmp/nginx/scgi\_temp  
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\_temp  
–http-log-path=/var/log/nginx-access.log  
–add-module=/usr/ports/www/nginx/work/ngx\_headers\_more\_module-0.14  
–with-http\_flv\_module --with-http\_gzip\_static\_module  
–with-http\_image\_filter\_module --with-http\_stub\_status\_module  
–with-pcre

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195695#msg-195695)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 5, 2011, 9:35am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/7 "2011-05-05T09:35:19Z")

</div>

On Wed, May 04, 2011 at 10:50:07PM -0400, stalkercn wrote:

> –http-scgi-temp-path=/var/tmp/nginx/scgi\_temp  
> –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\_temp  
> –http-log-path=/var/log/nginx-access.log  
> –add-module=/usr/ports/www/nginx/work/ngx\_headers\_more\_module-0.14  
> –with-http\_flv\_module --with-http\_gzip\_static\_module  
> –with-http\_image\_filter\_module --with-http\_stub\_status\_module  
> –with-pcre

There was a bug when nginx was built --without-http\_cache, but this is  
not your case. Could you try nginx-1.0.0 without third-party module  
ngx\_headers\_more\_module ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 4, 2011, 8:27am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/8 "2011-05-04T08:27:22Z")

</div>

On Tue, May 03, 2011 at 11:10:53PM -0400, stalkercn wrote:

> anyone can help me?

Could you show “nginx -V” output ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 4:46am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/9 "2011-05-06T04:46:05Z")

</div>

nginx: nginx version: nginx/1.0.1  
nginx: built by gcc 4.2.1 20070719 [FreeBSD]  
nginx: configure arguments: --prefix=/usr/local/etc/nginx  
–with-cc-opt=‘-I /usr/local/include’ --with-ld-opt=‘-L /usr/local/lib’  
–conf-path=/usr/local/etc/nginx/nginx.conf  
–sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid  
–error-log-path=/var/log/nginx.log --user=www --group=www --with-debug  
–http-client-body-temp-path=/var/tmp/nginx/client\_body\_temp  
–http-fastcgi-temp-path=/var/tmp/nginx/fastcgi\_temp  
–http-proxy-temp-path=/var/tmp/nginx/proxy\_temp  
–http-scgi-temp-path=/var/tmp/nginx/scgi\_temp  
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\_temp  
–http-log-path=/var/log/nginx-access.log --with-http\_gzip\_static\_module  
–with-http\_stub\_status\_module --with-pcre

I decrease the fastcgi buffer size and increase the amount of buffers:  
fastcgi\_buffer\_size 64k;  
fastcgi\_buffers 64 64k;

but a ‘too big header’ error still apears:

[debug] upstream split a header line in FastCGI records  
[error] upstream sent too big header while reading response header  
from upstream

btw,php is working with Zend-Optimizer,whether this condition can make  
the headers bigger than its real size?

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195960#msg-195960)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 6:43am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/10 "2011-05-06T06:43:15Z")

</div>

On Thu, May 05, 2011 at 10:45:21PM -0400, stalkercn wrote:

> –http-scgi-temp-path=/var/tmp/nginx/scgi\_temp  
> [debug] upstream split a header line in FastCGI records  
> [error] upstream sent too big header while reading response header  
> from upstream

Only fastcgi\_buffer\_size is relevant here.  
Could you set it to 512k and make request with debug log ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 8:34am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/11 "2011-05-06T08:34:55Z")

</div>

[http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html](http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html)

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195989#msg-195989)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 8:53am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/12 "2011-05-06T08:53:27Z")

</div>

[http://www.toofiles.com/zh/rawfilesdownload-documents-conf-nginx.html](http://www.toofiles.com/zh/rawfilesdownload-documents-conf-nginx.html)

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195996#msg-195996)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 8:42am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/13 "2011-05-06T08:42:57Z")

</div>

On Fri, May 06, 2011 at 02:34:03AM -0400, stalkercn wrote:

> [http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html](http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html)

According to this log nginx uses 4k fastcgi\_buffer\_size.  
Could you show your configuration ?

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 9:00am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/14 "2011-05-06T09:00:14Z")

</div>

On Fri, May 06, 2011 at 02:34:03AM -0400, stalkercn wrote:

> [http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html](http://www.toofiles.com/zh/rawfilesdownload-documents-log-nginx.html)

nginx does not merge locations as Apache does, so:

```
    location / {
        root /home/www;
        index index.php index.html;
    }

    location ~ \.php$ {
        root /home/www;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/www$fastcgi_script_name;
        include fastcgi_params;

        fastcgi_temp_file_write_size 10m;
        fastcgi_busy_buffers_size 512k;
        fastcgi_buffer_size 512k;
        fastcgi_buffers 16 512k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_intercept_errors on;
        fastcgi_next_upstream error invalid_header timeout http_500;
    }

```

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 9:23am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/15 "2011-05-06T09:23:08Z")

</div>

ooh a foolish fault!  
But as seem as proxy mode,between two contiguous lines in the debug  
log,the time is 4-5 seconds,I dont know why?

eg:  
2011/05/06 15:14:10 [debug] 86514#0: \*101 http upstream request:  
“/general/mytable/intel\_view/index.php?”  
2011/05/06 15:14:10 [debug] 86514#0: \*101 http upstream dummy handler  
2011/05/06 15:14:10 [debug] 86514#0: timer delta: 100  
2011/05/06 15:14:10 [debug] 86514#0: posted events 0000000000000000  
2011/05/06 15:14:10 [debug] 86514#0: worker cycle  
2011/05/06 15:14:10 [debug] 86514#0: kevent timer: 299900, changes: 0  
2011/05/06 15:14:14 [debug] 86514#0: kevent events: 1  
2011/05/06 15:14:14 [debug] 86514#0: kevent: 8: ft:-1 fl:0020  
ff:00000000 d:5816 ud:0000000801102150  
2011/05/06 15:14:14 [debug] 86514#0: \*101 http upstream request:  
“/general/mytable/intel\_view/index.php?”  
2011/05/06 15:14:14 [debug] 86514#0: \*101 http upstream process header  
2011/05/06 15:14:14 [debug] 86514#0: \*101 malloc:  
0000000801302000:524288

the full log:  
[http://www.toofiles.com/zh/rawfilesdownload-documents-7z-nginx\_log.html](http://www.toofiles.com/zh/rawfilesdownload-documents-7z-nginx_log.html)

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,195999#msg-195999)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 10:03am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/16 "2011-05-06T10:03:16Z")

</div>

OK，I’ll find out php problem,thanks anyway.

Posted at Nginx Forum:

> **[Re: How to avoid "too big header" issue?](https://forum.nginx.org/read.php?2,192785,196007#msg-196007)**
>
> There's hundreds of "setcookie('xxx','yyy')" lines in one of my php page,the size of these cookies is about 2-10KB,so nginx always throw a typical "502 bad gateway". my solutionA is: add this to nginx.conf:...

---

<div class="post-metadata">

**Author:** ![stalkercn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@stalkercn](https://www.ruby-forum.com/u/stalkercn)\
**Post date:** [May 6, 2011, 9:39am UTC](https://www.ruby-forum.com/t/how-to-avoid-too-big-header-issue/206067/17 "2011-05-06T09:39:47Z")

</div>

On Fri, May 06, 2011 at 03:22:23AM -0400, stalkercn wrote:

> 2011/05/06 15:14:10 [debug] 86514#0: worker cycle  
> the full log:  
> [http://www.toofiles.com/zh/rawfilesdownload-documents-7z-nginx\_log.html](http://www.toofiles.com/zh/rawfilesdownload-documents-7z-nginx_log.html)

7z format is certainly not the best way to pack report logs.  
There is old good gzip: it’s enough.

As to delay, it seems that is is PHP delay.

–  
Igor S.
