遇到问题--jsp---Nginx转发https导致静态资源无法加载--This request has been blocked
2018-11-22 15:41
2051 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q383965374/article/details/84341288
转发请注明出处:遇到问题–jsp—Nginx转发https导致静态资源无法加载–This request has been blocked
遇到问题
使用nginx作转发,强制tomcat部署的web项目使用https访问。
导致静态资源无法加载访问。
如图
浏览器报错如下:
Mixed Content: The page at 'https://xxxx.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://xxxx//res/css/style.css'. This request has been blocked; the content must be served over HTTPS.
原因
这是因为浏览器的机制,当https的页面中有其他http的请求时,会被锁定和忽略,甚至不会经过nginx。
所以即使nginx设置了转发规则也没用。
为什么静态资源发起的请求是http的呢?
一般是使用绝对路径导致的。
我的请求方式如下:
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <link rel="stylesheet" href="<%=basePath%>/res/css/style.css" type="text/css" media="all"></link></head>
解决方法一
可以在相应的页面的里加上这句代码,意思是自动将http的不安全请求升级为https
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
解决方法二
相对协议
对于同时支持HTTPS和HTTP的资源,引用的时候要把引用资源的URL里的协议头去掉,浏览器会自动根据当前是HTTPS还是HTTP来给资源URL补上协议头的,可以达到无缝切换。
例如:
<link rel="stylesheet" href="/res/css/style.css" type="text/css" media="all"></link></head> 或者 <link rel="stylesheet" href="res/css/style.css" type="text/css" media="all"></link></head>
转发请注明出处:遇到问题–jsp—Nginx转发https导致静态资源无法加载–This request has been blocked
相关文章推荐
- android WebView加载不出网页内容This request has been blocked; the content must be served over HTTPS.
- 解决Nginx做主服务器与Tomcat整合下无法加载JSP中静态资源的问题
- android WebView加载不出网页内容This request has been blocked; the content must be served over HTTPS.
- HTTPS调用百度地图API提示“BMap未定义, This request has been blocked; the content must be served over HTTPS.,was
- This request has been blocked; the content must be served over HTTPS.
- 在jsp中使用response.getOutputStream()导致报错问题getOutputStream() has already been called for this response
- Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.
- https下 http的会被阻塞 This request has been blocked; the content must be served over HTTPS.
- 用maven搭建springmvc项目时,jsp页面无法加载js或者css等静态资源
- Nginx将utf8编码的url解码成\x的16进制格式导致无法匹配静态文件的问题处理
- spring MVC js css图片等静态资源无法加载问题
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决
- SpringMVC在JSP中加载CSS等静态资源问题
- UIWebView无法用loadRequest加载页面 错误提示:App Transport Security has blocked a cleartext HTTP ...
- 解决使用SpringMVC时,css、js、image等静态资源无法加载的问题
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决(转)
- spring mvc 整合CKEditor遇到无法加载CKEditor的JS等资源问题
- nginx动静态分离以及配置https(安全组强行切换以及导致的问题解决)
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决