uwsgi + nginx + flask:文件下载后上游过早closures

我在烧瓶上创build了一个端点,它从数据库查询(远程数据库)生成一个电子表格,然后在浏览器中下载。 烧瓶不会抛出任何错误。 Uwsgi不抱怨。

但是,当我检查nginx的error.log,我看到很多

2014/12/10 05:06:24 [error] 14084#0:* 239436上游过早closures连接,同时从上游读取响应头,客户端:34.34.34.34,服务器:me.com,请求:“GET /下载/导出.csv HTTP / 1.1“,上游:”uwsgi://0.0.0.0:5002“,主机:”me.com“,引用来源:” https://me.com/download/export.csv “

我部署uwsgi像

uwsgi --socket 0.0.0.0:5002 --buffer-size=32768 --module server --callab app 

我的nginxconfiguration:

 server { listen 80; merge_slashes off; server_name me.com www.me.cpm; location / { try_files $uri @app; } location @app { include uwsgi_params; uwsgi_pass 0.0.0.0:5002; uwsgi_buffer_size 32k; uwsgi_buffers 8 32k; uwsgi_busy_buffers_size 32k; } } server { listen 443; merge_slashes off; server_name me.com www.me.com; location / { try_files $uri @app; } location @app { include uwsgi_params; uwsgi_pass 0.0.0.0:5002; uwsgi_buffer_size 32k; uwsgi_buffers 8 32k; uwsgi_busy_buffers_size 32k; } } 

这是一个nginx或uwsgi问题,或两者?

这是uwsgi在启动时所说的

  *** Starting uWSGI 2.0 (64bit) on [Wed Dec 10 15:20:23 2014] *** compiled with version: 4.6.3 on 20 January 2014 16:57:53 os: Linux-3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013 nodename: me.com machine: x86_64 clock source: unix detected number of CPU cores: 1 current working directory: /home/server.py detected binary path: /usr/local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! your processes number limit is 3781 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to TCP address 0.0.0.0:5002 fd 3 Python version: 2.7.3 (default, Sep 26 2013, 20:13:52) [GCC 4.6.3] Python main interpreter initialized at 0x23632b0 python threads support enabled your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 202864 bytes (198 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x23632b0 pid: 30636 (default app) *** uWSGI is running in multiple interpreter mode *** 

这是uwsgi在下载请求中说的

[pid:30643 | app:0 | req:763/763] 33.33.33.33(){56 2982字节} [Wed Dec 10 15:09:59 2014] GET /download/test.xlsx =>生成5564字节在392 msecs通过sendfile()(HTTP / 1.1 200)在510个字节的7个头(核心0上的0个开关)