HTTPS頁面里動態(tài)的引入HTTP資源柑司,比如引入一個js文件畔规,會被直接block掉的.在HTTPS頁面里通過AJAX的方式請求HTTP資源,也會被直接block掉的疯汁。
image
Mixed Content: The page at 'xxx' was loaded over HTTPS, but requested an insecure resource 'xxx'. This request has been blocked; the content must be served over HTTPS.
解決辦法:
頁面的head中加入:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
意思是自動將http的不安全請求升級為https
注意:在需要的網(wǎng)頁上加上面的語句疯淫,
其它不需要的網(wǎng)頁不需要加地来,不然會出錯的。
CSP設(shè)置upgrade-insecure-requests
好在 W3C 工作組考慮到了我們升級 HTTPS 的艱難熙掺,在 2015 年 4 月份就出了一個 Upgrade Insecure Requests
的草案未斑,他的作用就是讓瀏覽器自動升級請求。
在我們服務(wù)器的響應(yīng)頭中加入:
header("Content-Security-Policy: upgrade-insecure-requests");