Created
May 2, 2017 20:08
-
-
Save flavioribeiro/f2f889973a21b9e58f071c073e0f5cc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes auto; | |
error_log stderr debug; | |
events { | |
worker_connections 1024; | |
multi_accept on; | |
use epoll; | |
} | |
http { | |
resolver 8.8.8.8 8.8.4.4 ipv6=off; | |
include /usr/local/nginx/conf/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /dev/stdout main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 60; | |
keepalive_requests 1000; | |
client_header_timeout 20; | |
client_body_timeout 20; | |
reset_timedout_connection on; | |
send_timeout 20; | |
gzip on; | |
gzip_types application/vnd.apple.mpegurl; | |
vod_mode remote; | |
vod_upstream_location /bucket; | |
vod_align_segments_to_key_frames on; | |
vod_dash_fragment_file_name_prefix "segment"; | |
vod_hls_segment_file_name_prefix "segment"; | |
vod_segment_duration 3000; | |
vod_last_modified_types *; | |
vod_metadata_cache metadata_cache 2048m; | |
open_file_cache max=1000 inactive=5m; | |
open_file_cache_valid 2m; | |
open_file_cache_min_uses 1; | |
open_file_cache_errors on; | |
aio on; | |
server { | |
listen 80; | |
server_name localhost; | |
location /bucket { | |
internal; | |
rewrite ^/bucket/(.*)/(hls|dash|hlsfmp4)/(.*)$ /nyt/$1/$3 break; | |
proxy_pass http://storage.googleapis.com; | |
proxy_set_header Host storage.googleapis.com; | |
} | |
location ~ ^/video-media/hlsfmp4/.+$ { | |
content_by_lua_block { | |
require "string"; | |
ngx.header["Access-Control-Allow-Headers"] = '*'; | |
ngx.header["Access-Control-Allow-Origin"] = '*'; | |
ngx.header["Access-Control-Allow-Methods"] = 'GET, HEAD, OPTIONS'; | |
hls_manifest = ngx.var.request_uri:gsub("fmp4", "") | |
hls_content = ngx.location.capture(hls_manifest) | |
init_segment_uri = "http://" .. ngx.var.host .. ngx.var.request_uri:gsub("hlsfmp4","dash"):gsub("index","init"):gsub("a1.m3u8","x3.mp4") | |
init_segment_header = "#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-MAP:URI=" .. init_segment_uri | |
if string.match(ngx.var.request_uri, "index") then | |
res, _ = hls_content.body:gsub("EXT-%-X%-PLAYLIST%-TYPE:VOD", init_segment_header):gsub("-a1.ts","-x3.m4s"):gsub("hls", "dash") | |
else | |
res, _ = hls_content.body:gsub("hls", "hlsfmp4") | |
end | |
ngx.print(res) | |
} | |
} | |
location ~ ^/video-media/hls/.+$ { | |
vod hls; | |
add_header Access-Control-Allow-Headers '*'; | |
add_header Access-Control-Allow-Origin '*'; | |
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS'; | |
expires max; | |
} | |
location ~ ^/video-media/dash/.+$ { | |
vod dash; | |
add_header Access-Control-Allow-Headers '*'; | |
add_header Access-Control-Allow-Origin '*'; | |
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS'; | |
expires max; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment