在https网站上用JS,socket.io,socket使用http,然后出现blocked:mixed-content
以下几种方法,解决 Firefox 显示“已阻止载入混合活动内容”的问题
方法一:
<link rel="stylesheet" href="http://www.2kb.com/bootstrap/3.3.5/css/bootstrap.min.css">
比如这里我用了bootcss的cdn,但是正常情况下这样写是会报blocked mixed-content错误的。
解决方法:
<link rel="stylesheet" href="//www.2kb.com/bootstrap/3.3.5/css/bootstrap.min.css">
这样的话浏览器就会根据你域名的请求来识别,比如https下他会自动请求https的资源,而http时,请求http的资源。
但是有可能他并不存在https的资源,但是我又想在Https下用这个cdn怎么办呢?
方法二:
加<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
这样他会在请求Http资源的时候先将他转成Https再请求。
方法三:
可以在nginx里面解决
在nginx可通过在server添加
# socket代理配置 location /2kb.com/ { proxy_pass http://w.2kb.com:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; }
#解决https请求http资源不可用的情况
add_header Content-Security-Policy upgrade-insecure-requests;
2KB项目(www.2kb.com,源码交易平台),提供担保交易、源码交易、虚拟商品、在家创业、在线创业、任务交易、网站设计、软件设计、网络兼职、站长交易、域名交易、链接买卖、网站交易、广告买卖、站长培训、建站美工等服务 |