2011-08-08 30 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

相關問題