XSendFile不会为Apache 2.2中的文件提供服务

boa*_*der 9 apache apache-modules

我正在使用mod_xsendfile(v0.12)来提供静态文件,其中Django根据用户和权限控制对文件的访问.

在我的conf文件中,我有:

XSendFile On
XSendFilePath e:/documents/

<Directory e:/Documents>
  Order allow,deny
  Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

在我的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
Run Code Online (Sandbox Code Playgroud)

在我的日志文件中,我得到:

[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
Run Code Online (Sandbox Code Playgroud)

在这个版本中mod_xsendfile,

XSendFileAllowAbove On
Run Code Online (Sandbox Code Playgroud)

生成错误:

Invalid command 'XSendFileAllowAbove', perhaps misspelled or defined by a module
not included in the server configuration
Run Code Online (Sandbox Code Playgroud)

我以为那是因为他们添加了XSendFilePath白名单.还有其他人上班吗?

nma*_*ier 13

不要自己设置Content-Length.在这种情况下,这只会混淆mod_wsgi之类的处理程序.mod_xsendfile本身将设置正确的Content-Length.

在Windows上,您不仅必须提供驱动器号,驱动器号必须实际为大写(IIRC)!

我有一个像这样的工作测试配置:

<Directory "E:/">
  XSendFile on
  XSendFilePath E:/localhosts
</Directory>
Run Code Online (Sandbox Code Playgroud)

我在E:/Apache2.2/htdocs/中的一个工作测试脚本如下所示:

<?php
  header('X-SendFile: E:/localhosts/archive.tar.bz2');
  header('Content-type: application/octet-stream');
  header('Content-disposition: attachment; filename="blob"');
?>
Run Code Online (Sandbox Code Playgroud)

XSendFileAllowAbove在一段时间后被删除,转而使用XSendFilePath