XSendFile 不会在 Apache 2.2 中提供文件
我正在使用 mod_xsendfile (v0.12) 来提供静态文件,其中 Django 根据以下内容控制对文件的访问用户和权限。
在我的conf文件中,我有:
XSendFile On
XSendFilePath e:/documents/
<Directory e:/Documents>
Order allow,deny
Allow from all
</Directory>
在我的django代码中,我设置了如下标头:
assert(isinstance(filename, FieldFile))
xsendfile = filename.name
if(platform.system() == 'Windows'):
xsendfile = xsendfile.replace('\\', '/')
response = HttpResponse()
response['X-Sendfile'] = xsendfile
mimetype = mimetypes.guess_type(xsendfile)[0]
response['Content-Type'] = mimetype
response['Content-Length'] = filename.size
在我的日志文件中,我得到:
[Fri Oct 22 08:54:22 2010] [error] [client 192.168.20.34] (20023)The given path
was above the root path: xsendfile: unable to find file:
e:/Documents/3/2010-10-20/TestDocument.pdf
在此版本的mod_xsendfile
中,
XSendFileAllowAbove On
生成错误:
Invalid command 'XSendFileAllowAbove', perhaps misspelled or defined by a module
not included in the server configuration
我认为那是因为他们添加了 XSendFilePath
白名单。还有其他人让这个工作吗?
I'm using mod_xsendfile (v0.12) to serve static files where Django is controlling access to the files based on users and permissions.
In my conf file, I have:
XSendFile On
XSendFilePath e:/documents/
<Directory e:/Documents>
Order allow,deny
Allow from all
</Directory>
In my django code, I set the headers like so:
assert(isinstance(filename, FieldFile))
xsendfile = filename.name
if(platform.system() == 'Windows'):
xsendfile = xsendfile.replace('\\', '/')
response = HttpResponse()
response['X-Sendfile'] = xsendfile
mimetype = mimetypes.guess_type(xsendfile)[0]
response['Content-Type'] = mimetype
response['Content-Length'] = filename.size
And in my log file I get:
[Fri Oct 22 08:54:22 2010] [error] [client 192.168.20.34] (20023)The given path
was above the root path: xsendfile: unable to find file:
e:/Documents/3/2010-10-20/TestDocument.pdf
In this version of mod_xsendfile
,
XSendFileAllowAbove On
generates the error:
Invalid command 'XSendFileAllowAbove', perhaps misspelled or defined by a module
not included in the server configuration
I assumed that was because they have added the XSendFilePath
white list. Anyone else got this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要自己设置 Content-Length。在这种情况下,这只会让 mod_wsgi 等处理程序感到困惑。
mod_xsendfile 本身将设置正确的内容长度。
在 Windows 上,您不仅必须提供驱动器号,而且驱动器号必须实际上为大写 (IIRC)!
我有一个像这样的工作测试配置:
E:/Apache2.2/htdocs/ 中的一个工作测试脚本如下所示:
XSendFileAllowAbove 不久前被删除,以支持 XSendFilePath
Do not set a Content-Length yourself. This will only confuse handlers such as mod_wsgi in this case.
mod_xsendfile will itself set the correct Content-Length.
On Windows you must not only provide the drive letter, the drive letter must be actually in upper-case (IIRC)!
I have a working test configuration like so:
One of my working test scripts in E:/Apache2.2/htdocs/ looks like this:
XSendFileAllowAbove was removed a while back in favor of XSendFilePath
大多数时候我都遇到了很多麻烦,我不得不配置 XSendfile 路径。
看看出了什么问题(跳到本文末尾查看结论和建议):
因此,基本上,对于 Windows 上的 X-Sendfile,请确保:
希望它对某人有帮助!
法比安
I've had a whole lot of trouble most of the times I had to configure XSendfile path.
Here is me testing several scenarios on Windows to see what was wrong (jump to the end of this post to see the conclusion ad recommendations):
So, basically, for X-Sendfile on Windows, make sure that:
Hope it helps someone!
Fabien