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 

posted @ 2019-03-25 15:59  Hiro-D  阅读(2310)  评论(0编辑  收藏  举报