文章目录[隐藏]

遇到的PHP云转码,M3U8切片出现无法跨域播放

以下是至今遇见的云转码跨域问题,解决方案如下

方案一

如果是宝塔Nginx环境

直接在你网站伪静态 如图设置

方案二

location / {
if ( $request_method = ‘OPTIONS’ ) {
add_header access-control-allow-headers range;
add_header access-control-allow-methods GET,POST,HEAD,OPTIONS;
add_header access-control-allow-origin *;
return 200;
}
add_header access-control-allow-origin *;
}

方案三

location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods ‘GET, POST, OPTIONS’;
add_header Access-Control-Allow-Headers ‘DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization’;
if ($request_method = ‘OPTIONS’) {
return 204;
}
}

 

express-ffmpeg云转码系统

    #单个ts后缀跨域
    location ~ .*\.ts$
    {
        add_header Access-Control-Allow-Origin *;
        proxy_pass http://IP:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr; 
    }

    #多个后缀跨域,比如m3u8和ts,中间用|分开
    location ~ .*\.(m3u8|ts)$
    {
        add_header Access-Control-Allow-Origin *;
        proxy_pass http://IP:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr; 
    }

 

网盘式云转码

    #单个ts后缀跨域
    location ~ .*\.ts$
    {
        add_header Access-Control-Allow-Origin *;
    }

    #多个后缀跨域,比如m3u8和ts,中间用|分开
    location ~ .*\.(m3u8|ts)$
    {
        add_header Access-Control-Allow-Origin *;
    }