ruby-on-rails - nginx + unicorn + Rails + 流媒体

标签 ruby-on-rails nginx audio-streaming x-accel-redirect

我正在尝试使用 nginx、unicorn 和 Rails 4 来流式传输音频。 我正在使用以下两个链接: onetwo 这就是我到目前为止所得到的 -->

nginx.conf

 location /protected/ {
            internal;
            alias /$1/;     #should end up evaluating the same thing
    }

    location / {
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Sendfile-Type X-Accel-Redirect;
            proxy_set_header X-Accel-Mapping ^/*=/protected/$1;
            proxy_pass http://127.0.0.1:<port>/;
    }

我从 Controller 发送文件:

send_file(/home/full/path/file.mp3, 
            :filename => "filename.mp3",
            :type => "audio/mpeg",
            :disposition => "inline",
            :stream => 'true',
            :buffer_size  => 4096)

现在,使用 unicorn 和 nginx 我可以听这首歌,但不能搜索。在没有 nginx 的情况下也会发生这种情况。我希望能够寻求。我发现将这两行放入 production.rb 将解决问题:

现在,在我的 production.rb 中,我有:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # specifically for nginx
config.middleware.insert 0, Rack::Sendfile, config.action_dispatch.x_sendfile_header # make sure it loads before any other middleware

但现在我收到 403 Forbidden 错误。有帮助吗?

最佳答案

找到解决方案了.. 所以基本上 Nginx 在该目录中工作,因此如果您无法使用 nginx 用户cd到该目录,那么您将收到 403 禁止错误。您可以使用 stat 进行确认。

sudo -u www-data stat /path

如果 nginx 用户无法访问该路径,则会失败。 然后,您可以使用gpasswd命令将用户添加到组并解决问题。

关于ruby-on-rails - nginx + unicorn + Rails + 流媒体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31314639/

相关文章:

ruby-on-rails - Rails 应用程序 GET 路线在生产模式下不起作用

ruby-on-rails - 如何以递归方式将 YAML 文件扁平化为 JSON 对象,其中键是点分隔的字符串?

reactjs - Nginx:在同一服务器上为多个 React 应用程序提供服务

java - 如何录制声音并将其设置为Java文件?

ios - AVPlayer 中的 SeekToTime 在转发时停止播放流式音频

ruby-on-rails - 推送到 Elastic Beanstalk 时出现 Rails bundle 错误

ruby-on-rails - 异步调用 Controller 操作以返回 URL 以与 image_tag 一起使用

php - 任何获得404 Not Found的AWS EB Laravel路由nginx/1.16.1

nginx - 如何在 Debian 服务器的子文件夹中使用 Sphinx 加载文档

c# - 如何在 Unity3D 中通过麦克风流式传输实时音频?