【问题标题】:nginx - upstream sent too big header while reading response header from upstreamnginx - 在从上游读取响应标头时,上游发送了太大的标头
【发布时间】:2020-01-15 21:49:27
【问题描述】:

我有一个用python和flask框架编写的电子商务项目,我在会话中保留购物车信息,当我尝试将产品添加到会话时,nginx给出了这个错误:

上游从上游读取响应头时发送的头太大,客户端:xx.xxx.xx.xxx,服务器:mysite.com,请求:“POST /add_to_cart HTTP/1.1”,上游:“uwsgi://unix :/path/uwsgi.sock:", 主机: "mysite.com"

当我在会话中有很多信息时会发生这种情况,

我尝试添加fastcgiproxy_buffer参数,但还是不行,这是我的nginx conf文件:

server {
  listen       443 ssl;
  server_name  mysite.com;

  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;
  }
} 

【问题讨论】:

  • 向我们展示您与会话相关的代码以及会话系统的设置方式。

标签: python linux nginx flask nginx-config


【解决方案1】:

如果您能够通过 curl 重构精确的 POST 请求或以其他方式测量实际标头大小,则可以为 uwsgi_buffer_size 指定适当的大小(与您的情况相关的指令)。

这是我的post,它对类似指令proxy_buffer_size 有一些见解。有许多 *_buffer_size 指令,每个类似“代理”的 NGINX 模块都有一个(fastcgi、proxy、uwsgi),但是您如何调整它们(以及它们的基本工作方式)是相同的。

你可以试试,不用测量,直接放在server块里:

uwsgi_buffer_size 16k; 
uwsgi_busy_buffers_size 24k; 

【讨论】:

  • 谢谢,它成功了。我必须使用uwsgi缓冲区参数,我不知道有这样的参数;),谢谢
  • 感谢 Danila,您的回答非常有帮助,解决了我的问题!我已经增加了 nginx 代理缓冲区大小和 fastcgi,但还需要增加 uwsgi 大小
猜你喜欢
  • 2017-04-09
  • 2015-10-26
  • 2019-12-21
  • 2021-02-04
  • 2018-12-14
  • 2014-11-03
  • 2019-12-09
  • 1970-01-01
相关资源
最近更新 更多