drupal7一套核心代码搭建多个站点

本文详细介绍了如何在Drupal7中设置两个站点,包括数据库配置、URL和Cookie域的修改,以及通过Nginx实现单点登录。同时,提供了解决用户头像地址关联的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

drupal 7的多站点设置:

假使有两个站点,site1.test.com,site2,test.com

首先复制sites/default -> sites/site1.test.com      sites/default -> sites/site2.test.com
在sites/site1.test.com/settings.php 下面修改代码:

$databases['default']['default'] = array (
        'database' => 'db_site1_test',
        'username' => 'root',
        'password' => 'root',
        'host' => 'localhost',
        'port' => '',
        'driver' => 'mysql',
        'prefix' => '',
);
// Read more about this variables in settings.php
$base_url = 'http://site1.test.com';
$cookie_domain = '.test.com'; // 这段能让网站单点登录,前提是多站点都是同一个域下的二级域

 

在sites/site2.test.com/settings.php 下面修改代码:

$databases['default']['default'] = array (
        'database' => 'db_site2_test',
        'username' => 'root',
        'password' => 'root',
        'host' => 'localhost',
        'port' => '',
        'driver' => 'mysql',
        'prefix' => array(
                'default'   => 'db_site2_test.',
                'users'     => 'db_site1_test.',
                'sessions'  => 'db_site1_test.',
                'role'      => 'db_site1_test.',
                'authmap'   => 'db_site1_test.',
                'users_roles'   => 'db_site1_test.',
        ),
);
$base_url = 'http://site2.test.com';
$cookie_domain = '.test.com';

nginx.conf设置

 server {
        listen       80;
        server_name  site1.test.com site2.test.com;

        location / {
            root   D:/WWW/drupal;
            index  index.html index.htm index.php;
        autoindex  on;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        location ~ \.php$ {
            root          D:/WWW/drupal;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

 

仅仅在settings.php中添加几行代码可以让单点登录操作变成小菜一碟。需要注意的是,这么做的话,其他和用户相关的信息也需要同样被共享,特别是如果你使用了profile模块,你需要同样共享profile_fields和profile_values表。
有一个问题你可以会遇到,就是你的用户头像的地址需要全部被关联到主站的用户头像地址上。要解决这个问题,我们只需要添加一个软连接就可以了:

<?php
ln
-s /usr/home/example.com/sites/default/files/pictures /usr/home/subsite.example.com/sites/default/files/pictures
?>

再次声明,这个方法在同一个域名下多个架设在同一组服务器上的网站上是可用的。浏览器由于安全考虑会禁止不同域名之间的网站互访cookie,这个时候, 你就需要寻找其他解决方案了,比如OpenID Provider, Single Sign-on, 或者 Bakery。
http://colblog.net/node/25/
http://www.drupalla.com/node/378
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值