I am trying to stream a static audio file and then download the same by doing some basic validations such as validating mobile number etc. I am using nginx+rails 4 + puma server for the same.
Request lands at Nginx, then Rails server (I do some basic validation) then use the send_file code(mentioned below) to send file to nginx back and then streaming/download start.
Issue is I am not able to stream the song plus some XL-Redirect related error is coming in nginx. Your help will be highly grateful as I need to stream large amount of songs i.e. high TPS i am looking forward. So, what's the best possible way.
RAILS CODE SNIPPET:
file_path = "/home/Co001.mp3"
aFile = File.new(file_path)
response.header['Content-Type'] = tone
response.headers['Content-Length'] = File.size aFile
file_name = "ringtone.mp3"
send_file(aFile,
:filename => file_name,
:type => "tone")
Nginx conf snippet:
keepalive_timeout 75 20;
# Virtual Host Configs
include /usr/local/nginx/mime.types;
upstream xyz {
# Path to Puma SOCK file
server unix:/home/ruby/rails_workspace/xyz/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 1212;
server_name xyz.pqr.com;
root /home/ruby/rails_workspace/xyz/public/;
#index index.html;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
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 ^/*=/$1;
proxy_redirect off;
}
# Logging --
access_log /usr/local/nginx/logs/access.log;
error_log /usr/local/nginx/logs/error.log notice;
error_log /usr/local/nginx/logs/error.log error;
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt|mp3)$ {
access_log off;
expires 30d;
}
}
Looking forward for support from your end. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire