前端 JS 解决m3u8直播拉流 跨域和403报错问题 反向代理 方法
首先把跨域的m3u8文件按原路径保存的你的本地目录下,示例如下
源:https://live.cctvfpm.cn/openlive/809a5c37a6c649f48c7f0bc37f218ca3.hd/playlist.m3u8?stream=9v7k2
本地服务器目录 third_live/openlive/809a5c37a6c649f48c7f0bc37f218ca3.hd/playlist.m3u8注意域名部分用目录名third_live替代,后面的路径保持不变
nginx vhost 站点配置加这一段
location ^~ /third_live/ { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,Keep-Alive,Origin,User-Agent,X-Requested-With,content-type,Authorization, x-ui-request,lang'; proxy_pass https://live.cctvfpm.cn/; proxy_set_header referer ""; }
3. 重启 nginx 就可以了
解析:主要原理是解决跨域 再就是清掉 referer
add_header 'Access-Control-Allow-Origin' '*';
proxy_set_header referer ""; screen.conf 配置参考 email search screnn.conf