kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
2k stars 439 forks source link

changing hostname inside m3u8 based on the requested hostname on multi server confs #1291

Open Sulieman9 opened 3 years ago

Sulieman9 commented 3 years ago

Hello There I have a working Kaltura vod server, all fine with it, but recentlly I wanted to ad a new virtual server to use other hostname for other website, and that's fine too. ex: cdn.foo.com and the other hostname is: v.boo.net

the only thing I can't understand and handle, is the URLs inside the v.boo.net is reffering to the first host: cdn.foo.com the questiom is how to make each host use the same host inside the m3u8 list file ? when request this: https://stream.raiadv.com/cdn/1.mp4.urlset/playlist.m3u8 :

`#EXTM3U

EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2374044,RESOLUTION=1278x720,FRAME-RATE=30.303,CODECS="avc1.640020,mp4a.40.2"

https://cdn.alarab.com/cdn/1.mp4/index-v1-a1.m3u8

EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=1296961,RESOLUTION=1278x720,CODECS="avc1.640020",URI="https://cdn.alarab.com/cdn/1.mp4/iframes-v1-a1.m3u8"

`

I need it to use: https://**stream.raiadv.com**/cdn/1.mp4/index-v1-a1.m3u8 beside: https://cdn.alarab.com/cdn/1.mp4/index-v1-a1.m3u8

attached confs:

` http { upstream fallback { server 127.0.0.1:443; }

server {

listen 443 ssl;
listen [::]:443 ssl;

ssl on;
ssl_certificate /usr/local/nginx/ssl/cdn.alarab.com.chained.crt;
ssl_certificate_key /usr/local/nginx/ssl/server.key;

server_name  cdn.foo.com;   
access_log  /dev/null;
error_log /usr/local/nginx/logs/stream-error.log;
    # vod settings
    vod_mode local;
    vod_fallback_upstream_location /fallback;
    vod_last_modified 'Sun, 19 Nov 2019 08:52:00 GMT';
    vod_last_modified_types *;
    vod_hls_master_file_name_prefix playlist;

    # vod caches
    vod_metadata_cache metadata_cache 30m;
    vod_response_cache response_cache 30m;

    # gzip manifests
    gzip on;
    gzip_types application/vnd.apple.mpegurl;

    # file handle caching / aio
    open_file_cache max=100000 inactive=10m;
    open_file_cache_valid 60m;
    open_file_cache_min_uses 1;
    open_file_cache_errors off;

    aio on;

    location ^~ /fallback/ {
        internal;
        proxy_pass http://fallback/;
        proxy_set_header Host $http_host;
    }

    location / {
        root /storage/;
        vod hls;
        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';
        expires 100d;
    }

location /securetest {
       alias /storage/;

    }

        location /hls1/ {
        vod hls;
        alias /storage/53media/flv/iphone/;
        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';
        vod_hls_master_file_name_prefix playlist;
        expires 8m;
    }
        location /hls3/ {
        vod hls;
        alias /storage/480/;
        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';
        vod_hls_master_file_name_prefix playlist;
        expires 8m;
    }
        location /hls4/ {
        vod hls;
        alias /storage/;
        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';
        vod_hls_master_file_name_prefix playlist;
        expires 8m;
    }
}

server {

listen 80 ;

ssl off;

server_name  v.boo.net; 
access_log  /dev/null;
error_log /usr/local/nginx/logs/stream-error.log;
    # vod settings
    vod_mode local;
    vod_fallback_upstream_location /fallback;
    vod_last_modified 'Sun, 19 Nov 2019 08:52:00 GMT';
    vod_last_modified_types *;
    vod_hls_master_file_name_prefix playlist;

    # vod caches
    #vod_metadata_cache metadata_cache 30m;
    #vod_response_cache response_cache 30m;

    # gzip manifests
    gzip on;
    gzip_types application/vnd.apple.mpegurl;

    # file handle caching / aio
    open_file_cache max=100000 inactive=10m;
    open_file_cache_valid 60m;
    open_file_cache_min_uses 1;
    open_file_cache_errors off;

    aio on;

    location ^~ /fallback/ {
        internal;
        proxy_pass http://fallback/;
        proxy_set_header Host $http_host;
    }

    location / {
        root /storage/cdn/;
        vod hls;
        add_header Access-Control-Allow-Headers '*';
        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
        add_header Access-Control-Allow-Origin '*';
        expires 100d;
    }

location /securetest {
       alias /storage/cdn/;

    }

}`  
mlevkov commented 3 years ago

why don't you use map and set functionalities for you to conform your host for every call?

SoccerPlaymm commented 2 years ago

server {

listen 443 ssl; listen [::]:443 ssl;

ssl on; ssl_certificate /usr/local/nginx/ssl/cdn.alarab.com.chained.crt; ssl_certificate_key /usr/local/nginx/ssl/server.key;

server_name cdn.foo.com;
access_log /dev/null; error_log /usr/local/nginx/logs/stream-error.log;

vod settings

vod_mode local;
vod_fallback_upstream_location /fallback;
vod_last_modified 'Sun, 19 Nov 2019 08:52:00 GMT';
vod_last_modified_types *;
vod_hls_master_file_name_prefix playlist;

# vod caches
vod_metadata_cache metadata_cache 30m;
vod_response_cache response_cache 30m;

# gzip manifests
gzip on;
gzip_types application/vnd.apple.mpegurl;

# file handle caching / aio
open_file_cache max=100000 inactive=10m;
open_file_cache_valid 60m;
open_file_cache_min_uses 1;
open_file_cache_errors off;

aio on;

location ^~ /fallback/ {
    internal;
    proxy_pass http://fallback/;
    proxy_set_header Host $http_host;
}

location / {
    root /storage/;
    vod hls;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    expires 100d;
}

location /securetest { alias /storage/;

}

    location /hls1/ {
    vod hls;
    alias /storage/53media/flv/iphone/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}
    location /hls3/ {
    vod hls;
    alias /storage/480/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}
    location /hls4/ {
    vod hls;
    alias /storage/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}

}

SoccerPlaymm commented 2 years ago

server {

listen 443 ssl; listen [::]:443 ssl;

ssl on; ssl_certificate /usr/local/nginx/ssl/cdn.alarab.com.chained.crt; ssl_certificate_key /usr/local/nginx/ssl/server.key;

server_name cdn.foo.com;
access_log /dev/null; error_log /usr/local/nginx/logs/stream-error.log;

vod settings

vod_mode local;
vod_fallback_upstream_location /fallback;
vod_last_modified 'Sun, 19 Nov 2019 08:52:00 GMT';
vod_last_modified_types *;
vod_hls_master_file_name_prefix playlist;

# vod caches
vod_metadata_cache metadata_cache 30m;
vod_response_cache response_cache 30m;

# gzip manifests
gzip on;
gzip_types application/vnd.apple.mpegurl;

# file handle caching / aio
open_file_cache max=100000 inactive=10m;
open_file_cache_valid 60m;
open_file_cache_min_uses 1;
open_file_cache_errors off;

aio on;

location ^~ /fallback/ {
    internal;
    proxy_pass http://fallback/;
    proxy_set_header Host $http_host;
}

location / {
    root /storage/;
    vod hls;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    expires 100d;
}

location /securetest { alias /storage/;

}

    location /hls1/ {
    vod hls;
    alias /storage/53media/flv/iphone/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}
    location /hls3/ {
    vod hls;
    alias /storage/480/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}
    location /hls4/ {
    vod hls;
    alias /storage/;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    vod_hls_master_file_name_prefix playlist;
    expires 8m;
}

}