diff --git a/app/controllers/cached_transcoded_stream_controller.rb b/app/controllers/cached_transcoded_stream_controller.rb index 8ce33282..46c1c844 100644 --- a/app/controllers/cached_transcoded_stream_controller.rb +++ b/app/controllers/cached_transcoded_stream_controller.rb @@ -7,9 +7,7 @@ def new private - def set_header - return unless nginx_senfile? - + def set_nginx_header response.headers["X-Accel-Redirect"] = File.join("/private_cache_media", @stream.transcode_cache_file_path.sub(Stream::TRANSCODE_CACHE_DIRECTORY.to_s, "")) end end diff --git a/app/controllers/stream_controller.rb b/app/controllers/stream_controller.rb index e142dc55..89ddaaec 100644 --- a/app/controllers/stream_controller.rb +++ b/app/controllers/stream_controller.rb @@ -2,7 +2,6 @@ class StreamController < ApplicationController before_action :find_stream - before_action :set_header def new if need_transcode? @stream.format @@ -14,11 +13,9 @@ def new private - # Let nginx can get value of media_path dynamically in the nginx config, - # when use X-Accel-Redirect header to send file. - def set_header - return unless nginx_senfile? - + def set_nginx_header + # Let nginx can get value of media_path dynamically in the nginx config, + # when use X-Accel-Redirect header to send file. response.headers["X-Media-Path"] = Setting.media_path response.headers["X-Accel-Redirect"] = File.join("/private_media", @stream.file_path.sub(File.expand_path(Setting.media_path), "")) end @@ -34,6 +31,8 @@ def nginx_senfile? def send_local_file(file_path) if nginx_senfile? + set_nginx_header + send_file file_path return end diff --git a/config/nginx/nginx.conf b/config/nginx/nginx.conf index 4df9d3c9..ef3951f8 100644 --- a/config/nginx/nginx.conf +++ b/config/nginx/nginx.conf @@ -58,7 +58,7 @@ http { location /private_cache_media/ { internal; - alias /tmp/cache/media_file/; + alias /app/tmp/cache/media_file/; } location / {