Nginx RTMP模块HLS Cors错误

时间:2018-03-26 09:31:17

标签: nginx cors

我正在使用NGINX RTMP模块设置HLS流。一切都很好。但是,当我尝试通过JWPlayer HLS流测试器访问流时,出现此错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://uk-lon.voxtl.com:8080/hls/luke/index.hls. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

我在Nginx配置中添加了正确的标签:

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

server {
    listen 8080;
    server_name uk-lon.voxtl.com;

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

        root /mnt/;

        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        }

        add_header Cache-Control no-cache;
    }
}
}

0 个答案:

没有答案