I use the Ckplayer player to implement the No ' Access-control-allow-origin ' header is present on the requested resource when playing the. m3u8 file in the HTML5 environment.
Find on the Internet that you need to add the Crossdomain.xml file in the root directory of the site, I also added, the result is still invalid. Finally groping for a long time to find the following solution (do not need to add Crossdomain.xml file) Modify nginx.conf
Modify the nginx.conf and add the Add_header Access-control-allow-origin under the Location/hls module *;
My nginx configuration is as follows.
rtmp {server {listen 1935; #监听的服务端口 chunk_size 4096;
#数据传输块的大小 #设置直播的application名称是hls application HLs {live on;
HLS on;
Hls_path/home/wwwroot/hls;
Hls_fragment 5s;
}} http{server {listen 80;
server_name Www.vmliveroom.io Vmliveroom.io;
Root "/home/wwwroot/liveroom/public";
include/usr/local/nginx/conf/enable-php-pathinfo.conf;
Location/{index index.html index.htm index.php l.php;
AutoIndex off;
if (!-e $request _filename) {rewrite ^ (. *) $/index.php?s=/$1 last; }} Location/hls {# Serve HLS fragments types {APPLICATION/VND
. Apple.mpegurl m3u8;
VIDEO/MP2T ts;
} root/home/wwwroot; Add_header Cache-coNtrol No-cache;
#添加下面一行 Add_header Access-control-allow-origin *;
} error_page 502 503 504/50x.html;
Location =/50x.html {root html;
}
}
}