【发布时间】:2018-08-14 09:44:26
【问题描述】:
我在Gunicorn 和lighttpd 后面使用Django。在Gunicorn 文档中,我将Lighttpd 配置为充当Gunicorn 的反向代理:
$SERVER["socket"] == "0.0.0.0:80" {
server.document-root = "/home/user/app"
server.errorlog = "/var/log/lighttpd/app-error.log"
accesslog.filename = "/var/log/lighttpd/app-access.log"
$HTTP["url"] !~ "^/static/" {
proxy.server = (
"" => (
(
"host" => "127.0.0.1",
"port" => 8888,
"allow-x-send-file" => "enable"
)
)
)
}
}
到目前为止一切顺利,甚至静态文件都可以正确提供。
现在我正在尝试使用标题X-Sendfile。在我的Django 代码中:
response['Content-Type'] = 'application/force-download'
response['Content-Disposition'] = f'attachment; filename={smart_str(send_name)}'
response['X-Sendfile'] = '/tmp/big-file.txt'
/tmp/big-file.txt 存在并且可由Lighttpd 进程访问。
每次我尝试以这种方式提供文件时,浏览器都会得到一个空响应;没有有效载荷和Content-Length: 0。
我从Lighttpd(我认为Django + Gunicorn 部分很好)那里找不到任何关于问题所在的错误。
我能做什么?我的错在哪里?
【问题讨论】:
标签: django lighttpd x-sendfile