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

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

猜你喜欢

转载自hao3721.iteye.com/blog/1930851