欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal7 d7 drupal Mixed content: load all resources via HTTPS to improve the security of your site 自己亲自做的有大用 有大大用 有大大大用 有大大大大用

Even though the initial HTML page is loaded over a secure HTTPS connection, some resources like images, stylesheets or scripts are being accessed over an insecure HTTP connection. Usage of insecure resources is restricted to strengthen the security of your entire site.

To resolve this issue, load all resources over a secure HTTPS connection.

可以看看    /node-admin/18901   


https:// 情况下,会发现 j页面里面 加载的 许多 css   js 都是 http

 所以 页面肯定显示不正常 


我们看 includes/bootstrap.inc 文件中 有关 $base_url  $base_root;

$http_protocol = $is_https ? 'https' : 'http';
$base_root = $http_protocol . '://' . $_SERVER['HTTP_HOST'];


 知道 关键点是 $is_https 这个变量

在  includes/bootstrap.inc  里面 又看到 

$is_https = drupal_is_https();

在  includes/bootstrap.inc  里面 打开  drupal_is_https() 函数 

function drupal_is_https() {
   
if($_SERVER['REMOTE_ADDR'] == '10.94.30.171'){ //测试的代码
     
var_dump($_SERVER);
   }
 
if($_SERVER['SERVER_PORT'] == 443){

   
return true;
 }
 
return isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
}


最后发现  https://主页面  时 $_SERVER['SERVER_PORT'] 是 80

且 $_SERVER['HTTPS'] 为空


可以见  /node-admin/18901  有大用


解决方法是:

1) 在 nginx的 naproxy.conf 文件的最后加上一行 

proxy_set_header   X-Forwarded-Proto $scheme;

  此时 $_SERVER['HTTP_X_FORWARDED_PROTO'] 的值 就是 https了,

(在 http://主页面 的情况下,$_SERVER['HTTP_X_FORWARDED_PROTO'] 的值 就是 http了)

  2) 此时 再修改 drupal_is_https() 函数 再加上 

 if ($_SERVER['HTTP_X_FORWARDED_PROTO']=='https') { return true;}

else {  return false; }


二 1) 同上面的 1) 

  2) 不用修改 drupal_is_https() 函数 在 http的某个虚似主机的配置文件中(或者httpd.conf ) 加上

   SetEnvIf X-Forwarded-Proto https HTTPS=on ,如下图,,,

  此时 drupal_is_https() 自然就可以正确的返回 true 或 false 了

 image.png



当然最后 nginx 和 apache 都要重启下

普通分类: