2011-08-08 28 views
13

我正在努力与send_file与rails 3.0.9运行红宝石1.9,乘客3.0.8在Apache的Ubuntu的清醒 xsendfile模块安装并加载到ApacheRails 3,apache&passenger,send_file发送零字节文件

root~# a2enmod xsendfile 
Module xsendfile already enabled 

它在正确的符号链接

lrwxrwxrwx 1 root root 32 Aug 8 11:20 xsendfile.load -> ../mods-available/xsendfile.load 

config.action_dispatch.x_sendfile_header = "X-Sendfile"设在我production.rb启用MODS-

用零个字节文件由send_file结果被发送到浏览器

filepath = Rails.root.join('export',"#{filename}.csv") 
if File.exists?(filepath) 
    send_file filepath, :type => 'text/csv' 
end 

回答

11

我相信以前的答案是不要去,因为据我所知,Apache不处理下载的正确方法所有这些解决方案都应用时,而不是导轨过程。这就是为什么看起来不适用的nginx指令。通过注释掉配置指令可以得到相同的结果。

另一个缺点(除了绑定rails进程太长时间)是当数据流由rails进程处理时,响应似乎不会发送内容长度头。所以用户不知道他们下载的文件有多大,也不知道需要多长时间(可用性问题)。

我能够得到它通过确保mod_sendfile工作被适当地包括在我的Apache配置装载,像这样(这将取决于你的Apache安装等):

LoadModule xsendfile_module /usr/lib64/httpd/modules/mod_xsendfile.so 
... 

# enable mod_x_sendfile for offloading zip file downloads from rails 
XSendFile on 
XSendFilePath/
+0

肖恩,我想你可能就在这里。这些配置选项不是x_sendfile模块的默认值。 – Rob

+0

它似乎XSendFile的默认值没有打开,但关闭。在这里查看可能的配置选项和默认值:https://tn123.org/mod_xsendfile/ – Cam

相关问题