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