Nginx upstream sent too big header while reading response header from upstream

前端 未结 1 1719
北荒
北荒 2020-12-17 17:34

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: ex         


        
相关标签:
1条回答
  • 2020-12-17 18:10

    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;
    }
    
    0 讨论(0)
提交回复
热议问题