【问题标题】:django through lighttpd + mod_proxy + gunicorn: X-Sendfile returns empty responsesdjango 通过 lighttpd + mod_proxy + gunicorn:X-Sendfile 返回空响应
【发布时间】:2018-08-14 09:44:26
【问题描述】:

我在Gunicornlighttpd 后面使用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


    【解决方案1】:

    在您尝试设置 X-Sendfile 之前,检查您的脚本是否已发送响应标头。

    您可以在 lighttpd 进程上使用 strace 来查看从后端接收到的内容,以及查看 lighttpd 是否正在尝试打开 '/tmp/big-file.txt'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      • 2013-12-29
      • 1970-01-01
      • 2020-01-18
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多