Mixed Content :混合内容

474 阅读1分钟

Mixed Content: The page at https://example.com/index.html was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint http://example.com/api/v1/user. This request has been blocked; the content must be served over HTTPS.

如上:在浏览器通过 http协议 & https协议 访问了两个不同的资源。除了会触发 "同源协议" 的跨域问题,还会触发 "混合内容" 的问题:如果使用 https 在浏览器中加载页面,浏览器会拒绝通过 http 加载任何资源。

解决办法:

  1. 升级 API http -> https(或者服务器 https -> http) 保持协议统一
  2. 为 API 做 https 代理, 例如 nginx、envoy 代理
  3. stackoverflow 上 提供<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> 解决方案,但部分浏览器不支持。(未验证)