http升級為https后,靜態資源失效和ajax請求跨域問題


把http升級以后,一打開原本的網站,會發現很多靜態資源失效了。

只需要在html頁面加入:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

2:ajax請求與顯示跨域

當發送ajax請求時報錯:

XMLHttpRequest cannot load 【ajax請求的服務器url】 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 【自己服務器】 is therefore not allowed access.

這個時候直接百度應該有很多種辦法可以解決

我選擇了在nginx中配置跨域支持功能;

還是在nginx.conf中加入代碼:

http {
 
  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Headers X-Requested-With;
  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

}

然后重啟nginx服務器即可

重啟nginx服務器命令:# /usr/local/nginx/sbin/nginx -s reload 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM