Our Nginx server is currently returning a 502 for a user, for our NodeJS based application and the error logs indicate:

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

This appears to be caused by a too large of a cookie (header exceeds 4K on request) and we aren't sure how to deal with this situation, beyond telling the user to clear their cookies for the site. Any suggestions on how to deal with this?

The proxy pass configuration in our nginx file:

location / {
    proxy_pass http://localhost:8081;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_set_header x-forwarded-host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-NginX-Proxy true;

A further test, by passing the Nginx instance, shows the upstream Node.JS server can handle the larger than 4KB file, suggesting the issue is at the Nginx level.

Our environment:

Express based Node.js 10.19.0 server, fronted by Nginx 1.14.0 on an Ubuntu based system. The application running on the Node.js server is using Quasar SSR.

1 Answer 1


The solution I ended going with was to increase the buffer for the header size to 16K, based on an article and Nginx documentation:

proxy_buffers         8 16k;  # Buffer pool = 8 buffers of 16k
proxy_buffer_size     16k;    # 16k of buffers from pool used for headers

To quote the specific texts from the documentation:

On proxy_buffers:

Syntax: proxy_buffers number size;
Default: proxy_buffers 8 4k|8k;
Context: http, server, location

Sets the number and size of the buffers used for reading a response from the proxied 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.

On proxy_buffer_size:

Syntax: proxy_buffer_size size;
Default: proxy_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 proxied 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.