我试着让X服务我的重附件卡皮斯特拉诺。我发现不适用于符号链接。我如何处理由Capistrano符号链接的文件夹中的文件?
我的网络服务器是apache2 +乘客
在我的production.rb里
config.action_dispatch.x_sendfile_header = "X-Sendfile"在我的控制员行动中
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我的文件系统结构(其中"->“表示”符号链接“,缩进表示子文件夹):
/var/www/myproject
releases/
....
current/ -> /var/www/myproject/releases/xxxxxxxxxxxx
app/
public/
private/
videos/ -> /home/ftp_user/videos我在XSendFilePath /#上的apache配置XSendFilePath也尝试了/home/ftp_user/视频
我的应用程序能够提供小文件,但对于大文件,它提供了一个NoMemoryError(未能分配内存)。
我认为它没有使用x-sendfile,因为如果我不使用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问题,或者我试图做一些不可能解决的符号链接问题。
编辑:按照已接受的答案,它“神奇地”开始工作!
我以这种方式创建了一个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正在以正确的方式为文件服务(也是非常重的文件)。
我知道这可能是一个安全问题,但我将尝试将其指向我的应用程序的最后一个版本,因为将它指向当前的符号链接不起作用。
发布于 2014-03-10 19:00:10
https://stackoverflow.com/questions/22115011
复制相似问题