我的烧瓶+ uwsgi + nginx应用程序有问题,只是我无法下载大于 ~1GiB 的文件(大小每次都是差异的几个字节)
我唯一能找到的错误是:
/var/log/uwsgi/app/updates.example.com.log
Wed Feb 25 15:48:31 2015 - uwsgi_response_sendfile_do() TIMEOUT !!!
IOError: write error
[pid: 22385|app: 0|req: 1/1] 94.113.167.6 () {42 vars in 961 bytes} [Wed Feb 25 16:19:22 2015] GET /download/file/63ac9e2a5952c1fbdccb143eec8769b6 => generated 0 bytes in 5606 msecs via sendfile() (HTTP/1.1 200) 6 headers in 261 bytes (3582 switches on core 0)
其他一切似乎都没问题
渔获物在哪里?我错过了一些chache / timeout配置???
Thx获取任何帮助
nginx app.conf:
server {
listen 80;
server_name updates.example.com;
root /home/user/updates.example.com;
access_log /home/user/updates.example.com/logs/access.log;
error_log /home/user/updates.example.com/logs/error.log;
location /doc {
index index.htm index.html;
alias /home/user/updates.example.com/site;
}
#Testing static download dirs
location /cache
{
alias /home/user/updates.example.com/cache;
}
location /repository
{
alias /home/user/updates.example.com/repository;
}
location / {
uwsgi_pass unix:///home/user/updates.example.com/server.sock;
include uwsgi_params;
}
}
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
app.py(例如简化)
from flask import Flask, jsonify, request, url_for, send_file, redirect
import os
app = Flask(__name__)
@app.route('/download/<string:sum>')
def download(sum):
download_path = os.path.join(app.config['CACHE_DIR'], sum)
if os.path.isfile(download_path):
#everything seems to be ok
#!FIXME this cannot be used, download crashes when file reaches 1Gib> using direct path in client now and special config in nginx
return send_file(download_path, attachment_filename=sum)
return jsonify({ 'message': 'Task failed'}), 500
if __name__ == '__main__':
app.run()
uwsgi app.ini
[uwsgi]
uid = user
logto = /home/user/updates.example.com/logs/uwsgi.log
master = true
chdir = /home/user/updates.example.com/
socket = server.sock
module = app
callable = app
plugins = python
#Fix for DB connection coruption
lazy = true
lazy-apps = true
答案 0 :(得分:1)
您应该根据documentation:
设置uwsgi_max_temp_file_size
设置
当启用缓冲来自uwsgi服务器的响应,并且整个响应不适合uwsgi_buffer_size和uwsgi_buffers指令设置的缓冲区时,响应的一部分可以保存到临时文件中。该指令设置临时文件的最大大小。一次写入临时文件的数据大小由uwsgi_temp_file_write_size指令设置。
此设置的默认值为1024 MB。