Nginx - Upstream Sent Too Big Header While Reading Response Header From Upstream

- 1 answer

I have a e-commerce project written in python and flask framework, I keep shopping cart information on session, when I try add product to session, nginx gives this error:

upstream sent too big header while reading response header from upstream, client:, server:, request: "POST /add_to_cart HTTP/1.1", upstream: "uwsgi://unix:/path/uwsgi.sock:", host: ""

This occurs when I have a lot of information in session,

I tried adding fastcgi and proxy_buffer parameters, but still not working, here is my nginx conf file:

server {
  listen       443 ssl;

  ssl_certificate       /path/nginx.pem;
  ssl_certificate_key   /path/nginx.key;

  include              /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam          /etc/letsencrypt/ssl-dhparams.pem;

  access_log      /path/access.log main;

  fastcgi_buffers  16 16k;
  fastcgi_buffer_size 32k;

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

  location /static/ {
    alias         /path/web/static/;
    access_log    off;
    index         index.html index.htm;

  location / {
    try_files       $uri @uwsgi;
    root            /path/www/;
    index           index.html index.htm;    

  location @uwsgi {
    include uwsgi_params;
    uwsgi_pass  unix:/path/web/uwsgi.sock;


If you're capable of reconstructing exact POST request via curl or otherwise measure the actual header size, you can specify the proper size for uwsgi_buffer_size (the directive that is related in your case).

Here's my post that has some insight into a similiar directive, proxy_buffer_size. There are many *_buffer_size directives, each "proxy"-like NGINX module has one (fastcgi, proxy, uwsgi), but how you approach their tuning (and how they essentially work) is the same.

You can try, without measurement, by placing directly in server block:

uwsgi_buffer_size 16k; 
uwsgi_busy_buffers_size 24k;