已回答此问题here。NGinx&Django,提供大文件(3GB +)
我在服务大文件下载/上传(3gb +)时遇到了一些问题。
因为我使用的是Django,我猜服务器端文件的问题可能来自Django或NGinx。
在我的Nginx启用的网站我有
server {
...
client_max_body_size 4G;
...
}
而且随着Django的,我服务于数据块中的文件大小:
def return_file(path):
filename = os.path.basename(path)
chunk_size = 8192
response = StreamingHttpResponse(FileWrapper(open(path), chunk_size), content_type=mimetypes.guess_type(path)[0])
response['Content-Length'] = os.path.getsize(path)
response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
return response
这种方法让我从600MB〜下载到通2.6Gb,但似乎下载在2.6Gb被截断。我跟踪误差:
2015/09/04 11:31:30 [error] 831#0: *553 upstream prematurely closed connection while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /chat/download/photorec.zip/ HTTP/1.1", upstream: "http://unix:/web/rsmweb/run/gunicorn.sock:/chat/download/photorec.zip/", host: "localhost", referrer: "http://localhost/chat/2/"
阅读一些帖子后,我增加了以下我的Nginx的conf:
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
但我买了一个*1
代替*553*
我同样的错误也认为它可能是一个Django数据库超时,所以我补充说:
DATABASE_OPTIONS = {
'connect_timeout': 14400,
}
但它也不起作用。 (通过开发服务器下载大约需要30秒)
感谢您的帮助!
我会尽量找到django的问题,但它不是登录/显示任何错误! – rsm
然后你需要做一些调试。我不是一个Python程序员,也不是一个编程问答网站,所以我没有更多的帮助。 – womble
我以为这是ServerFault的问题,而不是S.O,因为它几乎与“服务器设置”有关,但是感谢您指出它,并感谢您的帮助! – rsm