项目最近访问地址由http转到https上,访问一些静态资源出现the content must be served over HTTPS.这些资源都是用的原http开头的地址,都需要变成https访问。

解决方案有3种
第一种,把所有涉及到需要访问的静态数据挨个有原http的地址换成https(不推荐)
第二种,可以在相应的页面的<head>里加上强制转换代码,把http访问都强制https访问
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
第三种,通过配置 Nginx 和 Tomcat来实现
在 Nginx的nginx.conf文件里加入proxy_set_header X-Forwarded-Proto $scheme;代码块
location ^~ /xx {
proxy_pass http://localhost:8080/xxx;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
在Tomcat的server.xml 的 Engine 模块里配置一个 Valve代码块
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
这样https就可以正常访问了。

项目从http切换到https后,遇到静态资源报错需通过HTTPS访问。解决方案包括手动替换链接、添加页面头部强制转换代码,或配置Nginx与Tomcat实现自动转换。

1932

被折叠的 条评论
为什么被折叠?



