nginx反向代理到Https后,请求Http资源报错blocked mixed-content

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Honnyee/article/details/88866986

第一种方法:

  <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

比如这里我用了bootcss的cdn,但是正常情况下这样写是会报blocked mixed-content错误的。

解决方法:

 <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

这样的话浏览器就会根据你域名的请求来识别,比如https下他会自动请求https的资源,而http时,请求http的资源。

但是有可能他并不存在https的资源,但是我又想在Https下用这个cdn怎么办呢?

第二种方法:

加<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

这样他会在请求Http资源的时候先将他转成Https再请求。

第三种方法:

可以在nginx里面解决

在nginx可通过在server添加

#解决https请求http资源不可用的情况

add_header Content-Security-Policy upgrade-insecure-requests;

解决

猜你喜欢

转载自blog.csdn.net/Honnyee/article/details/88866986
今日推荐