我在 Flask 上创建了一个端点,它从数据库查询(远程数据库)生成电子表格,然后将其作为下载发送到浏览器中。Flask 不会抛出任何错误。Uwsgi 不会抱怨。
但是当我检查 nginx 的 error.log 时,我看到很多
2014/12/10 05:06:24 [错误] 14084#0:*239436 上游在读取上游的响应头时过早关闭连接,客户端:34.34.34.34,服务器:me.com,请求:“GET /download/export.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
我的 nginx 配置:
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 字节} [2014 年 12 月 10 日,星期三 15:09:59] GET /download/test.xlsx => 通过 sendfile() 在 392 毫秒内生成 5564 字节(HTTP/1.1 200)7 个标头,510 字节(核心 0 上的 0 个交换机)