Rails3 + Nginx:使用send_file(m4v)提供文件

问题描述:

我使用Rails3和Nginx。Rails3 + Nginx:使用send_file(m4v)提供文件

我通过控制器提供文件:uploads action。

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

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; 
    } 
    } 
} 

当我请求视频文件的http:// {ip}/components/{id} /content/host_bg.m4v文件我在我的Chrome控制台中看到错误(单个请求产生4行) enter image description here

我能解决这个问题吗?我想我的nginx配置不完整。 请注意,我可以播放视频,但不能按预期的方式投放视频(例如,javascript HTML5 jPlayer只能播放一次视频,然后停止播放,重复播放可从其他http位置播放)。谢谢!

我加

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

我的nginx的conf文件,它的工作原理。