一些相關(guān)資源:
Drupal 實(shí)在是一個(gè)很強(qiáng)大的網(wǎng)絡(luò)操作系統(tǒng),它內(nèi)建的多站點(diǎn)安裝機(jī)制非常強(qiáng)大,但也比較復(fù)雜,下面我來總結(jié)一下本站(robinlord.org)的多站點(diǎn)安裝方案。
很多朋友購買的虛擬主機(jī)對數(shù)據(jù)庫或者空間或者可以綁定的域名或者能夠設(shè)置的子域名限制非常厲害,但是使用 drupal 這一切將不再是問題。Drupal 可以使用一個(gè)數(shù)據(jù)庫來安裝多個(gè)站點(diǎn),這個(gè)只要在安裝過程中設(shè)定數(shù)據(jù)表前綴即可。
我來分析下本站(robinlord.org)的結(jié)構(gòu)。本站目前共使用同一套 Drupal
代碼搭建了三個(gè)獨(dú)立的站點(diǎn):blogs.robinlord.org、drupal.robinlord.org、
drupal.robinlord.org/hanhua。是的,沒錯(cuò),最后那個(gè)是獨(dú)立的站點(diǎn),不是一個(gè)路徑,這個(gè)是利用 drupal
的子目錄來做獨(dú)立站點(diǎn)的,本文的關(guān)鍵也就在這一切的實(shí)現(xiàn)。
本站是采用泛域名解析+.htacess的方案來實(shí)現(xiàn)的。
首先需要了解什么是泛域名解析,然后把所有的 *.roginlord.org 解析到站點(diǎn)的 web
根目錄(public_html),接著在根目錄下建立 drupal 目錄做為 drupal 的代碼目錄,接著在根目錄下的 .htacess 添加
urlrewrite 規(guī)則,把對 drupal.robinlord.org 和 blogs.robinlord.org 的請求全部定向到
drupal 目錄,其它的二級域名目錄這樣做。至于 drupal.robinlord.org/hanhua ,則是建立一個(gè)名為 hanhua
軟鏈接到 drupal 目錄(Linux 主機(jī),windows 主機(jī)再行研究)。比如 /public_html/hanhua 就是到
/public_html/drupal 的軟鏈接,同時(shí)在給 drupal.robinlord.org 做url重寫時(shí)避開對 hanhua
的重寫,就實(shí)現(xiàn)了。
下面是站點(diǎn)的目錄結(jié)構(gòu):
public_html/ --|
|-- drupal/ #[目錄]這個(gè)是 drupal 的程序目錄
|--hanhua/ #[目錄]這個(gè)是到 drupal 的軟鏈接
|--.htacess #[文件]這里配置目錄的 URL 重寫規(guī)則
下面是根目錄下 .htacess 的內(nèi)容:
<IfModule mod_rewrite.c>
RewriteEngine on
#重寫二級域名的路徑
RewriteCond %{HTTP_HOST} ^blogs".robinlord".org$
RewriteRule ^(.*)$ drupal/$1 [L]
RewriteCond %{HTTP_HOST} ^drupal".robinlord".org$
#對于子目錄獨(dú)立站點(diǎn)的配置
RewriteCond %{REQUEST_URI} !^hanhua
RewriteRule ^(.*)$ drupal/$1 [L]
</IfModule>
這樣就實(shí)現(xiàn)了多個(gè)站點(diǎn)的訪問,下面是多站點(diǎn)的安裝及公用用戶數(shù)據(jù)的設(shè)置。
首先,在安裝之前手動建立好各個(gè)站點(diǎn)的配置文件,遵循多站點(diǎn)目錄的命名規(guī)則。本站則建立了如下幾個(gè)目錄:
sites/--|
|-- blogs.robinlord.org
|-- drupal.robinlord.org
|-- drupal.robinlord.org.hanhua
在每個(gè)目錄手動建立相應(yīng)的 settings.php ,下面是 blogs.robinlord.org 的 settings.php 配置文件中需要手動設(shè)定的地方,其他配置在安裝過程中會自動設(shè)置。
$db_url = 'mysql://username:password@localhost/databasename';
$db_prefix = array(
'default' => 'blogs_',
'users' => 'shared_',
'access' => 'shared_',
'authmap' => 'shared_',
'sessions' => 'shared_',
'profile_fields' => 'shared_',
'profile_values' => 'shared_',
'languages' => 'shared_',
'locales_source' => 'shared_',
'locales_target' => 'shared_',
);
$base_url = 'http://blogs.robinlord.org';
$cookie_domain = 'robinlord.org';
$db_url 是數(shù)據(jù)庫配置。
$db_prefix 設(shè)定表前綴,default 設(shè)定站點(diǎn)默認(rèn)的表前綴,其他的則是數(shù)據(jù)表的名稱及其對應(yīng)的前綴設(shè)定,一般都設(shè)為 'shared_'。
$base_url 設(shè)定站點(diǎn)根域名,這個(gè)必須根據(jù)具體情況設(shè)置,負(fù)責(zé)站點(diǎn)路徑可能會出錯(cuò)。
$cookie_domain 這個(gè)就是多站點(diǎn)公用登陸的關(guān)鍵,設(shè)置為站點(diǎn)的根域,即可實(shí)現(xiàn)在多站點(diǎn)登陸一次即可。當(dāng)然還需要公用 user 和 session 相關(guān)的表,這個(gè)前面已經(jīng)配置好了。
設(shè)定好配置文件后,就可以開始安裝進(jìn)程。因?yàn)橐呀?jīng)設(shè)定了數(shù)據(jù)庫配置,所以安裝程序會直接跳過這些設(shè)置的頁面而直接開始安裝。