【发布时间】:2016-08-28 06:06:22
【问题描述】:
我正在为我们的 python web 应用程序配置 uwsgi+nginx。 我想添加 X-Sendfile 仿真(参见http://uwsgi-docs.readthedocs.io/en/latest/Snippets.html):
[uwsgi]
collect-header = X-Sendfile X_SENDFILE
response-route-if-not = empty:${X_SENDFILE} static:${X_SENDFILE}
现在我访问我们的网站,使用 sendfile() 正确响应了内容。唯一的缺陷是缺少 Content-Type,即使我已经在 wsgi 的响应中明确设置了它。我尝试了很多方法,我发现的唯一解决方法是:
[uwsgi]
collect-header = X-Sendfile-Content-Type X_SENDFILE_CONTENT_TYPE
collect-header = X-Sendfile X_SENDFILE
response-route-if-not= empty:${X_SENDFILE_CONTENT_TYPE} addheader:Content-Type: ${X_SENDFILE_CONTENT_TYPE}
response-route-if-not = empty:${X_SENDFILE} static:${X_SENDFILE}
这可行,但有点傻。我真的希望内容类型可以由文件的扩展名确定。有可能吗?
【问题讨论】:
标签: python mime-types uwsgi x-sendfile