Capistrano酒店&安培;的X SENDFILE [英] Capistrano & X-Sendfile

查看:298
本文介绍了Capistrano酒店&安培;的X SENDFILE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的X SENDFILE工作与Capistrano的服务我沉重的附件。我发现X SENDFILE不与符号链接工作。我怎么能处理由Capistrano的符号链接的文件夹里面的文件呢?

I'm trying to make X-Sendfile work for serving my heavy attachments with capistrano. I found that X-Sendfile is not working with symlinks. How could I handle the files inside a folder symlinked by Capistrano so?

我的Web服务器的Apache2 +乘客

my web server is apache2 + passenger

在我的 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

我的文件系统结构的(其中一个 - >代表符号链接和缩进意味着子文件夹):

my filesystem structure (where a "->" stands for "symlink" and indentation means subfolder):

/var/www/myproject
  releases/
  ....
  current/ -> /var/www/myproject/releases/xxxxxxxxxxxx
    app/
    public/
    private/
      videos/ -> /home/ftp_user/videos

我的 Apache的配置
    XSendFile上
    XSendFilePath / #also试图/家庭/ FTP_USER /视频

my apache config XSendFile on XSendFilePath / #also tried /home/ftp_user/videos

我的应用程序能够为小文件,但大的,它提供了NoMemoryError(无法分配内存)

My application is able to serve small files, but with big ones it gives a NoMemoryError(failed to allocate memory)

我觉得它不使用X发送文件,因为该行为是相同的,如果我不使用它。

I think it's not using x-sendfile, because the behavior is the same if I don't use it.

下面是我试图服务于文件的响应头

Here are the response headers of the file i'm trying to serve

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的问题,或者如果我试图做的符号链接问题的东西是不可能的。

I really don't know how to debug it, if it's a x-sendfile issue or if I'm trying to do something impossible for the symlinks problem

编辑:
继在接受一个建议的答案,它的神奇开始工作!

我创建了一个Capistrano的任务是这样的:

I created a capistrano task this way:

 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后运行它,所以我在重新启动后运行,由专人。

I didn't manage to run it after finalize_update, so i run it after the restart, by hand.

和我纠正这样我的Apache配置:

And i corrected my apache configuration in this way:

XSendFilePath /var/www/my_application

(我是指的x发送文件到FTP文件夹之前)

(before i was pointing x-sendfile to the ftp folder)

在我的响应头也现在的X SENDFILE没有出现,我得到了一个206 - 部分内容,但一切似乎工作和apache在正确的方式(也很沉重文件)送达文件

In my response headers also now X-Sendfile is not appearing, and i got a 206 - partial content, but everything seems to work and apache is serving files in the right way (also very heavy files).

我知道这可能是一个安全问题,但我会尽量把它指向我的应用程序的原因,而是指向当前符号链接的最后一个版本是行不通的。

I know this can be a security issue, but i will try to point it to the last release of my application cause pointing it to the current symlink is not working.

推荐答案

也许我找到了解决办法。你是如何让你的符号链接?

Maybe I found a solution. How did you make your symlinks?

也许你做了 LN -S ,这是不够的。

maybe you did ln -s, and it's not enough

这里他们建议使用 LN -nFs ,所以他承认它是你在链接的目录

Here they suggest using ln -nFs, so he recognizes it's a directory that you are linking in

这篇关于Capistrano酒店&安培;的X SENDFILE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆