HLTML5 Play HLs stream (. m3u8 file) Cross-domain access to No Access-control-allow-origin solution

Source: Internet
Author: User

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;
 }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.