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