分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

http升级为https后,静态资源失效和ajax请求跨域问题

发布时间:2023-09-06 02:36责任编辑:郭大石关键词:http跨域

把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 

http升级为https后,静态资源失效和ajax请求跨域问题

原文地址:https://www.cnblogs.com/a565810497/p/10594264.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved