I am trying to stream audio using using nginx, unicorn, and rails 4. I am using following these two links : one and two and this is what I have got so far -->
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>/;
}
I send file from my controller as :
send_file(/home/full/path/file.mp3,
:filename => "filename.mp3",
:type => "audio/mpeg",
:disposition => "inline",
:stream => 'true',
:buffer_size => 4096)
Now, using unicorn and nginx I am able to listen to the song, but not seek. This was happening with out nginx as well. I want to be able to seek. This I found that putting these two lines in production.rb will solve the issue :
So now, in my production.rb I have :
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
But now I get 403 Forbidden error. Any help anyone ?