2012-03-14 5 views
1

私はNginxでRails3を使用しています。Rails3 + Nginx:send_file(m4v)でファイルを提供

私は、controller:uploadsアクションによってファイルを提供します。

class BannersController < ApplicationController 
    ... # authentication 
    def uploads 
    send_file '{localFilePath}', :disposition => 'inline' 
    end 
end 

は、私が環境/ production.rbでこのライン

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

のコメントを解除します。

私も初期化子内のMIMEタイプ 'M4V' を定義した/ mime_types.rb私はビデオファイルのhttpを要求すると

Mime::Type.register "video/mp4", :m4v 
MIME::Types.add(MIME::Type.from_array("video/mp4", %(m4v))) 

私のnginxの構成は、この

http { 
    ... # ruby-1.9.3-p0 
    include mime.types; 
    default_type application/octet-stream; 
    sendfile on; 
    keepalive_timeout 65; 
    gzip on; 
    server { 
    client_max_body_size 30M; 
    listen 80; 
    server_name ... 
    root ... 
    passenger_enabled on; 
    rails_env production; 
    location ~ ^/(assets)/ { 
     root ... 
     gzip_static on; 
     expires max; 
     add_header Cache-Control public; 
    } 
    } 
} 

次のようになります// {ip}/components/{id} /content/host_bg.m4vファイルChromeのコンソールにエラーが表示されます(1回のリクエストで4行生成) enter image description here

それを修正できますか?私は自分のnginxの設定が完了していないと思います。 ビデオは再生できますが、期待どおりに機能していないことに注意してください(例:javascript HTML5 jPlayerは動画を1回再生して停止し、他のhttpの場所から繰り返し再生できます)。ありがとう!

答えて

0

私はnginxのconfのファイルに

passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /var/www/=/files/; 
location /files/ { 
    internal; 
    alias /var/www/; 
} 

を追加し、それが動作します。

関連する問題