我安装了 apache dev 头文件:
sudo apt-get install apache2-prefork-dev
Run Code Online (Sandbox Code Playgroud)
下载并编译模块,如下所述:http : //tn123.ath.cx/mod_xsendfile/
将以下行添加到 /etc/apache2/mods-available/xsendfile.load:
LoadModule xsendfile_module /usr/lib/apache2/modules/mod_xsendfile.so
Run Code Online (Sandbox Code Playgroud)
将此添加到我的 VirtualHost:
<VirtualHost *:80>
XSendFile on
XSendFilePath /path/to/protected/files/
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作启用模块:
sudo a2enmod xsendfile
Run Code Online (Sandbox Code Playgroud)
然后我重新启动了Apache。然后这段代码仍然只是为我提供了一个 0 字节的空文件:
file_path = '/path/to/protected/files/some_file.zip'
file_name = 'some_file.zip'
response = HttpResponse('', mimetype='application/zip')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(file_path)
return response
Run Code Online (Sandbox Code Playgroud)
Apache 错误日志中也没有与 XSendFile 相关的内容。我究竟做错了什么?