我正在尝试让 X-Sendfile 使用 capistrano 来处理我的繁重附件。我发现 X-Sendfile 不适用于符号链接。我如何处理 Capistrano 符号链接的文件夹内的文件?
我的网络服务器是apache2+passenger
in my 生产.rb:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
in my 控制器动作:
filename = File.join([Rails.root, "private/videos", @lesson.link_video1 + ".mp4"])
response.headers["X-Sendfile"]= filename
send_file filename, :disposition => :inline, :stream => true, :x_sendfile => true
render nothing: true
my 文件系统结构(其中“->”代表“符号链接”,缩进表示子文件夹):
/var/www/myproject
releases/
....
current/ -> /var/www/myproject/releases/xxxxxxxxxxxx
app/
public/
private/
videos/ -> /home/ftp_user/videos
my 阿帕奇配置X 发送文件
XSendFilePath / #也尝试过/home/ftp_user/videos
我的应用程序能够提供小文件,但对于大文件,它会给出 NoMemoryError(无法分配内存)
我认为它没有使用 x-sendfile,因为如果我不使用它,行为是相同的。
这是我尝试提供的文件的响应标头
Accept-Ranges:bytes
Cache-Control:private
Connection:Keep-Alive
Content-Disposition:inline
Content-Range:bytes 0-1265/980720989
Content-Transfer-Encoding:binary
Content-Type:video/mp4
Date:Sat, 01 Mar 2014 13:24:19 GMT
ETag:"70b7da582d090774f6e42d4e44ae3ba5"
Keep-Alive:timeout=5, max=97
Server:Apache/2.4.6 (Ubuntu)
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Powered-By:Phusion Passenger 4.0.37
X-Request-Id:22ff0a30-c2fa-43fe-87c6-b9a5e7da12f2
X-Runtime:0.008150
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block
我真的不知道如何调试它,如果这是一个 x-sendfile 问题或者如果我试图对符号链接问题做一些不可能的事情
EDIT:按照已接受答案中的建议答案,“神奇地”开始工作了!
我这样创建了一个 capistrano 任务:
task :storage_links do
on roles(:web), in: :sequence, wait: 2 do
#creo i link simbolici alle risorse
within "/var/www/my_application/current/private" do
execute :ln, "-nFs", "/home/ftp_user/videos"
end
end
end
我没有设法在 Finalize_update 之后运行它,所以我在重新启动后手动运行它。
我以这种方式更正了我的 apache 配置:
XSendFilePath /var/www/my_application
(在我将 x-sendfile 指向 ftp 文件夹之前)
在我的响应标头中,现在 X-Sendfile 也没有出现,我得到了 206 - 部分内容,但一切似乎都正常,apache 正在以正确的方式提供文件(也是非常重的文件)。
我知道这可能是一个安全问题,但我会尝试将其指向我的应用程序的最后一个版本,因为将其指向当前的符号链接不起作用。