how to fix upstream sent too big header while reading response header from upstream?

前端 未结 2 864
野性不改
野性不改 2021-01-18 14:32

I have this error in my log :

upstream sent too big header while reading response header from upstream

And I tried to add

proxy_buffer_size           


        
相关标签:
2条回答
  • 2021-01-18 15:33

    upstream sent too big header while reading response header from upstream is nginx's generic way of saying "I don't like what I'm seeing"

    1. Your upstream server thread crashed
    2. The upstream server sent an invalid header back
    3. The Notice/Warnings sent back from STDERR broke their buffer and both it and STDOUT were closed

    3: Look at the error logs above the message, is it streaming with logged lines preceding the message? PHP message: PHP Notice: Undefined index: Example snippet from a loop my log file:

    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 3rd line (from the 20 previous errors) the buffer limit was hit, broke, and the next thread wrote in over it. Nginx then closed the connection and returned 502 to the client.

    2: log all the headers sent per request, review them and make sure they conform to standards (nginx does not permit anything older than 24 hours to delete/expire a cookie, sending invalid content length because error messages were buffered before the content counted...)

    examples 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: verify, or make a script log, to ensure your thread is reaching the correct end point and not exiting before completion.

    0 讨论(0)
  • 2021-01-18 15:37

    Usually this parameters fix "upstream sent too big header" issue, and you dont need huge values for them :) And set them for http or server blocks, not location.

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

    Also sometimes FirePHP for Firefox creates large headers, try to disable it temporarily.

    0 讨论(0)
提交回复
热议问题