解决M3U8提示has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header

环境:
后台:springboot_xxx.jar
代理:nginx
前端:vue
视频流:hls(m3u8)
视频播放器:vue-video-player

"vue-video-player": "^5.0.2",
"videojs-contrib-hls": "^5.15.0",

问题描述:
VUE按网上教程已经销毁播放流,在Windows电脑的chrome没问题,但是在苹果电脑的chrome和Windows的uc浏览器里不能二次播放,需要清空缓存才能播放。

destroyed() {
    this.$destroy();
  },
  

解决方案:
在nginx加以下配置:

 location ~* \.(m3u8|ts)$ {
                proxy_cache off;                                   # 禁用代理缓存
                expires -1;                                        # 禁用页面缓存
                proxy_pass http://example.com;                     # 反代目标 URL
                sub_filter_last_modified off;                      # 删除原始响应里的浏览器缓存值
                sub_filter_once off;                               # 替换所有匹配内容
                sub_filter_types *;                                # 匹配任何 MIME 类型

        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
此插件为跨域插件,打开后可跨域访问接口,旧版浏览器可直接拖到扩展程序中安装,新版浏览器需要将扩展名修改成rar并解压,然后点击“加载已解压的扩展程序”安装。 ======================插件概述谷歌译文====================== 轻松将(Access-Control-Allow-Origin:*)规则添加到响应标头。 允许CORS:通过Access-Control-Allow-Origin,您可以轻松地在Web应用程序中执行跨域Ajax请求。 只需激活插件并执行请求。默认情况下(在JavaScript API中),CORS或跨源资源共享在现代浏览器中被阻止。安装此加载项将使您可以解除阻止此功能。请注意,将插件添加到浏览器后,默认情况下它处于非活动状态(工具栏图标为灰色C字母)。如果要激活加载项,请按一次工具栏图标。图标将变为橙色的C字母。 ======================插件概述谷歌译文====================== ========================插件概述原文======================== Easily add (Access-Control-Allow-Origin: *) rule to the response header. Allow CORS: Access-Control-Allow-Origin lets you easily perform cross-domain Ajax requests in web applications. Simply activate the add-on and perform the request. CORS or Cross Origin Resource Sharing is blocked in modern browsers by default (in JavaScript APIs). Installing this add-on will allow you to unblock this feature. Please note that, when the add-on is added to your browser, it is in-active by default (toolbar icon is grey C letter). If you want to activate the add-on, please press on the toolbar icon once. The icon will turn to orange C letter. ========================插件概述原文========================
这个错误信息说明在发送请求时,服务器返回的响应头中没有包含Access-Control-Allow-Origin字段,导致浏览器拒绝接受该响应。这是由于跨域访问(Cross-Origin Resource Sharing,CORS)的限制所引起的。 为了解决这个问题,可以添加一个名为CorsConfig的配置类,其中配置了允许跨域访问的规则。具体做法是使用addCorsMappings方法将允许跨域访问的规则添加到CorsRegistry中,可以设置allowedOriginPatterns为"*",表示允许来自所有域的请求;allowedHeaders设置为CorsConfiguration.ALL,表示允许所有请求头;allowedMethods设置为CorsConfiguration.ALL,表示允许所有请求方法;allowCredentials设置为true,表示允许发送身份验证信息;maxAge设置为3600,表示设置响应缓存的最大时间。通过这个配置类,服务器会在响应头中添加Access-Control-Allow-Origin字段,从而允许跨域访问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [has been blocked by CORS policy: No ‘Access-Control-Allow-Originheader is present on the ...](https://blog.csdn.net/qq_45800640/article/details/118422632)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [corsyusha:简单快速的代理,可在针对现有API进行原型设计时绕过CORS问题,而不必担心CORS](https://download.csdn.net/download/weixin_42176612/18261495)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决前后端跨域报错:has been blocked by CORS policy: No ‘Access-Control-Allow-Origin](https://blog.csdn.net/wsaicyj/article/details/127814374)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值