【问题标题】:Rails3+Nginx: Serving files with send_file (m4v)Rails3+Nginx:使用 send_file (m4v) 提供文件
【发布时间】:2012-03-30 23:08:12
【问题描述】:

我使用带有 Nginx 的 Rails3。

我通过控制器提供文件:上传操作。

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

我取消注释这一行

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

在环境/production.rb 中。

我还在我的初始化程序/mime_types.rb 中定义了一个 mime 类型“m4v”

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 行)

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

【问题讨论】:

    标签: ruby-on-rails-3 video nginx sendfile


    【解决方案1】:

    我加了

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

    到我的 nginx conf 文件,它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-10
      • 2013-06-27
      • 2014-01-12
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 2015-10-19
      相关资源
      最近更新 更多