为什么我的 https:// 请求取消,改为 http://,导致混合请求错误?

Emm*_*uel 5 javascript https angularjs mixed-content

我有一些简单的延迟加载 javascript:

script.type = 'text/javascript';
script.src = 'https://example.com/'+urlToJavascript;
script.onreadystatechange = callback;
script.onload = callback;   
head.appendChild(script);
Run Code Online (Sandbox Code Playgroud)

SSL 在我的域https://example.com/上运行。尽管https在 script.src 中,我还是收到了这个混合内容错误:

The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure script 'http://example.com/js/lazyScript.js'. This request has been blocked; the content must be served over HTTPS.

我运行console.log(script),它显示:

<script type="text/javascript" src="https://example.com/js/lazyScript.js"></script>
Run Code Online (Sandbox Code Playgroud)

然后我转到检查员的网络选项卡,发现提出了最初的请求,https://example.com/js/lazyScript.js但随后取消了,然后是对不安全的请求,http://example.com/js/lazyScript.js然后由于混合内容而被阻止。

我以前从未遇到过这种情况,也不知道为什么会发生这种情况。

发生这种情况的任何原因?

小智 3

这可能是由于服务器级别的一些重写造成的。我也遇到了同样的问题,是 nginx 以某种方式将 url 转换回 http。尝试直接在浏览器中加载资源 URL,看看是否发生重定向。如果是,请返回服务器并修复重定向。