[英]flask + nginx + uwsgi_response_sendfile_do() TIMEOUT
我的燒瓶+ 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配置???
感謝任何幫助
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
您應該根據文檔設置uwsgi_max_temp_file_size
設置:
當啟用緩沖來自uwsgi服務器的響應,並且整個響應不適合uwsgi_buffer_size和uwsgi_buffers指令設置的緩沖區時,響應的一部分可以保存到臨時文件中。 該指令設置臨時文件的最大大小。 一次寫入臨時文件的數據大小由uwsgi_temp_file_write_size指令設置。
此設置的默認值為1024 MB。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.