«В запрошенном ресурсе отсутствует заголовок« Access-Control-Allow-Origin ».» при попытке получить доступ к прямой трансляции VOD - PullRequest
0 голосов
/ 06 мая 2019

Я пытаюсь добавить функциональность VOD в проект. У меня есть настройка и сервер NGINX с nginx-rtmp-модулем и nginx-vod-модулем. Моя проблема возникает при запросе ресурса, созданного nginx-vod-module, из модуля hls.js npm.

Я немного растерялся, когда устанавливаю заголовки CORS, но, похоже, это не решает проблему.

worker_processes  auto;
error_log logs/error.log debug;
events {
    worker_connections  1024;
}

# RTMP configuration
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # record stream to folder /film/
            record all;
            record_path /film;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}

http {
    sendfile off;
    tcp_nopush on;
    default_type application/octet-stream;

    server {
        listen 8080;

        location /hls {
            # Disable cache
            add_header Cache-Control no-cache;

            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';

            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

            root /mnt/;
        }
    }

    server {
        listen 8384;

        # vod caches
        vod_metadata_cache metadata_cache 256m;
        vod_response_cache response_cache 128m;

        # vod settings
        vod_mode local;
        vod_segment_duration 2000; # 2s
        vod_align_segments_to_key_frames on;

        #file handle caching / aio
        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;

        location /vod/ {
            alias /film/;
            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;
        }
    }
}

Все отлично работает с '/ hls', но кажется, что с '/ vod' все по-другому. Если вам нужна дополнительная информация, не стесняйтесь спрашивать.

Спасибо

...