kaltura / nginx-vod-module

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

Remote Configuration – Fallback on Proxy #956

Open reformhaus opened 5 years ago

reformhaus commented 5 years ago

Many thanks first of all for the great tool. I have now tried a little and have the following requirement: I synchronize my media files from Origin_A to Storage_B. Storage_B is configured as vod_upstream_location in nginx-vod-module. Playing from remote location works fine! I would now like to have assets that are not yet available on Storage_B (sync running) retrieved from Origin_A. My previous tests were not successful:

location /hls/  {                        
            vod hls;
            vod_mode remote;
            vod_upstream_location /remote;
            vod_cache_buffer_size 8m;

            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 ^~ /remote/hls/ {
            internal;       
            proxy_pass https://storage_b.blob.core.windows.net;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host storage_B.blob.core.windows.net;
            proxy_intercept_errors on;

            error_page 404 502 = @origina;
        }

location @origina {

                #rewrite ^/hls/(.+)$ /$1 break;
                proxy_pass http://origina.com;
        }
erankor commented 5 years ago

This is not supported, nginx-vod-module will get the 404 and fail the request. You may be able to solve it using mapped mode - nginx-vod-module will hit some upstream server that "knows" whether the sync completed or not, and return a working URL to the MP4.

dynamic2500 commented 5 years ago

Hi ReformHaus,

you can try this solution:

this block must be in http scope

upstream origin { storage_b.blob.core.windows.net; origina.com backup; } #########################

location /hls/ {
vod hls; vod_mode remote; vod_upstream_location /remote; vod_cache_buffer_size 8m;

        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 ^~ /remote/hls/ { internal;
proxy_pass https://origin; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host storage_B.blob.core.windows.net; proxy_next_upstream error timeout http_401 http_403 http_404 http_500 http_502 http_503 http_504; }

My concept is using upstream for proxy_pass in progress of module, it will sub-request to /remote location and waiting response data from there. So if you using upstream, the proxy_pass module will try next_upstream before return hls location

the limitation of this solution is all upstreams must the same scheme and Host Header but i think this limitation is very easy to resolve