How do I fix the upstream sent too large a header when reading the response header up?

I have this error in my log:

upstream sends too large header when reading upstream response header

And I tried to add

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

      

for my nginx.conf http block but doesn't work

I also tried to add

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;

      

to my conf file, but I couldn't find the location of ~ .php $ {

So wondering how can I do this? adding

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;

      

in the manual php block gives me nginx: [emerg] unknown directive "location" in / etc / nginx / nginx.conf: 6

+3


source to share


2 answers


Usually these parameters fix the "upstream header sent too big" problem and you don't need huge values ​​for them :) And set them to http or server blocks, not location.

server {
...
    fastcgi_buffers  16 16k;
    fastcgi_buffer_size  32k;
}

      



Also sometimes FirePHP for Firefox generates big headers, please disable it temporarily.

+12


source


upstream sent too big header while reading response header from upstream

is nginx's common way of saying "I don't like what I see"

  • Upstream Server Stream Failure
  • The upstream server sent an invalid header back
  • The notification / warnings sent from STDERR broke their buffer and both were closed. STDOUT has been closed.

3: Look at the error logs above the message, is it being broadcast with the logged lines preceding the message? PHP message: PHP Notice: Undefined index:

An example snippet from my log file loop:

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

      

you can see in the third line (out of 20 previous errors) the buffer limit was cracked, broke, and the next thread wrote on top of it. Then Nginx closed the connection and returned 502 to the client.

2: write down all the headers sent on request, review them and make sure they are standards compliant (nginx does not allow anything more than 24 hours for cookie deletion / expiration, sending invalid content length as error messages are buffered to content counted ...)



Examples of

include:

<?php
//expire cookie
setcookie ( 'bookmark', '', strtotime('2012-01-01 00:00:00') );
// nginx will refuse this header response, too far past to accept
....
?>

      

and this:

<?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: check or create a script log to make sure your thread reached the desired endpoint and didn't exit before finishing.

+2


source







All Articles