热搜: | 激活| 时序| mos|
快捷导航 发布入口

m3u8视频跨域播放教程-Access-Control-Allow-Origin’ header

[复制链接]
查看: 3301|回复: 0

566

主题

182

回帖

1635

积分

管理员

积分
1635
QQ
发表于 2021-11-5 16:49:45 | 显示全部楼层 |阅读模式 来自 湖南省岳阳市 移动
m3u8视频跨域播放教程-解决跨域问题:Nginx提示CORS :No ‘Access-Control-Allow-Origin’ header 解决办法


2、解决方案
被CORS策略阻止的只有字体,只需要nginx配置字体跨域就可以。就不用配置其它跨域了。毕竟:Access-Control-Allow-Origin * 跨域是很危险的。

说明:nginx.conf配置Ok了,需要重启nginx。


nginx中Access-Control-Allow-Origin 其它跨域配置
添加代码:

  1. #
  2. # 用于nginx的开放式CORS配置
  3. #
  4. location / {
  5.      if ($request_method = 'OPTIONS') {
  6.         add_header 'Access-Control-Allow-Origin' '*';
  7.         add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  8.         #
  9.         # 自定义标题和标题各种浏览器*应该*可以,但不是
  10.         #
  11.         add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  12.         #
  13.         # 告诉客户这个飞行前信息有效期为20天
  14.         #
  15.         add_header 'Access-Control-Max-Age' 1728000;
  16.         add_header 'Content-Type' 'text/plain; charset=utf-8';
  17.         add_header 'Content-Length' 0;
  18.         return 204;
  19.      }
  20.      if ($request_method = 'POST') {
  21.         add_header 'Access-Control-Allow-Origin' '*';
  22.         add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  23.         add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  24.         add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
  25.      }
  26.      if ($request_method = 'GET') {
  27.         add_header 'Access-Control-Allow-Origin' '*';
  28.         add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  29.         add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  30.         add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
  31.      }
  32. }
复制代码
详细教程:
第一步打开宝塔,网站配置文件,拉到最下面倒数第二行以上添加,上面代码


2、注意格式对齐,



温馨提示:本站无需登入,即可回复帖子,发帖和回复请勿涉及违法等行为!网罗天下电脑(wltxdn.com)
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

精彩推荐

网罗天下让分享更简单

  • 反馈建议:admin@wltxdn.com
  • 工作时间:周一到周日 09:00-21:00
185-7316-8656

关注我们

Copyright   ©2018-2022  wltxdn Inc.  Powered by©Wltxdn  技术支持:网罗天下电脑    ( 湘ICP备2021015364号 )