WordPress中怎么開啟多站點(diǎn)支持及Nginx的重寫規(guī)則配置

wordpress3.0及以上版本可以直接使用多站點(diǎn),它可以:

1、只安裝一個(gè)WordPress程序即可創(chuàng)建多個(gè)wordpress站點(diǎn),可以是子域名也可以是子目錄。

2、可以有獨(dú)立的博客后臺,獨(dú)立的博客地址。

3、管理員可設(shè)置開放哪些主題給站點(diǎn)使用。

4、管理員可配置插件給每個(gè)站點(diǎn)使用。

5、多個(gè)站點(diǎn)之間共用“用戶數(shù)據(jù)庫表”,也就是表 wp_usermeta 和 wp_users,其他的為獨(dú)立數(shù)據(jù)庫表。

wordpress多站點(diǎn)的配置方法:

1、首先,備份網(wǎng)站的數(shù)據(jù)庫,以防出現(xiàn)意外時(shí)恢復(fù)(一般可忽略)。

2、打開wordpress的根目錄下的wp-config.php文件,在
require_once(abspath . ‘wp-settings.php’);
前面加上以下代碼:

define(‘wp_allow_multisite’,true);

3、進(jìn)入wordpress后臺,”工具”-> 點(diǎn)擊”配置網(wǎng)絡(luò)”

ps:如果您要使用二級域名的形式,可以到“設(shè)置”->“常規(guī)”里面,把站點(diǎn)地址(url)的www.去掉。

WordPress中怎么開啟多站點(diǎn)支持及Nginx的重寫規(guī)則配置

4、點(diǎn)擊安裝后,按照提示做好相關(guān)的配置

5、配置好,再次進(jìn)入后臺,在頭部將出現(xiàn)“我的站點(diǎn)”->“管理網(wǎng)絡(luò)”的選項(xiàng)菜單,接下來您可以管理或者創(chuàng)建站點(diǎn),也可以開啟主題或者插件給其他站點(diǎn)使用。

WordPress中怎么開啟多站點(diǎn)支持及Nginx的重寫規(guī)則配置

6、如果要給站點(diǎn)綁定其他域名,可以安裝 wordpress mu domain mapping 插件。

nginx多站點(diǎn)rewrite(重寫)規(guī)則
wordpress多站點(diǎn)模式可以被應(yīng)用在多種方式上。其中最常用的是在”子目錄”模式或者”二級域名”模式上。
nginx提供了兩種特殊的指令:”x-accel-redirect”和”map”,使用這兩個(gè)指令可以使得wordpress多站點(diǎn)的網(wǎng)絡(luò)服務(wù)實(shí)現(xiàn)偽靜態(tài)功能。

wordpress多站點(diǎn)使用子目錄重寫規(guī)則:
配置中jb51.net修改為自己的站點(diǎn)域名。

map?$uri?$blogname{ ?~^(?p<blogpath>/[^/]+/)files/(.*)?$blogpath?; } ? map?$blogname?$blogid{ ?default?-999; ? ?#ref:?http://wordpress.org/extend/plugins/nginx-helper/ ?#include?/var/www/wordpress/wp-content/plugins/nginx-helper/map.conf?; } ? server?{ ?server_name?jb51.net?; ? ?root?/var/www/jb51.net/htdocs; ?index?index.php; ? ?#多站點(diǎn)配置 ?location?~?^(/[^/]+/)?files/(.+)?{ ?try_files?/wp-content/blogs.dir/$blogid/files/$2?/wp-includes/ms-files.php?file=$2?; ?access_log?off;?log_not_found?off;?expires?max; ?} ? ?#avoid?php?readfile() ?location?^~?/blogs.dir?{ ?internal; ?alias?/var/www/jb51.net/htdocs/wp-content/blogs.dir?; ?access_log?off;?log_not_found?off;?expires?max; ?} ? ?if?(!-e?$request_filename)?{ ?rewrite?/wp-admin$?$scheme://$host$uri/?permanent;? ?rewrite?^(/[^/]+)?(/wp-.*)?$2?last;? ?rewrite?^(/[^/]+)?(/.*.php)?$2?last;? ?} ? ?location?/?{ ?try_files?$uri?$uri/?/index.php?$args?; ?} ? ?location?~?.php$?{ ?try_files?$uri?=404; ?include?fastcgi_params; ?fastcgi_pass?php; ?} ? ?#此處可以繼續(xù)添加偽靜態(tài)規(guī)則 }</blogpath>

wordpress多站二級域名重寫規(guī)則:
配置中jb51.net修改為自己的站點(diǎn)域名。

map?$http_host?$blogid?{ ?default??-999; ? ?#ref:?http://wordpress.org/extend/plugins/nginx-helper/ ?#include?/var/www/wordpress/wp-content/plugins/nginx-helper/map.conf?; ? } ? server?{ ?server_name?jb51.net?*.jb51.net?; ? ?root?/var/www/jb51.net/htdocs; ?index?index.php; ? ?location?/?{ ?try_files?$uri?$uri/?/index.php?$args?; ?} ? ?location?~?.php$?{ ?try_files?$uri?=404; ?include?fastcgi_params; ?fastcgi_pass?php; ?} ? ?#wpmu?files ??location?~?^/files/(.*)$?{ ????try_files?/wp-content/blogs.dir/$blogid/$uri?/wp-includes/ms-files.php?file=$1?; ????access_log?off;?log_not_found?off;??expires?max; ??} ? ?#wpmu?x-sendfile?to?avoid?php?readfile() ?location?^~?/blogs.dir?{ ?internal; ?alias?/var/www/jb51.net/htdocs/wp-content/blogs.dir; ?access_log?off;?log_not_found?off;?expires?max; ?} ? ?#此處可以繼續(xù)添加偽靜態(tài)規(guī)則 }

備注

“map”部分可以應(yīng)用于小站點(diǎn)。大站點(diǎn)的多站點(diǎn)應(yīng)用可以使用 nginx-helper wordpress插件 。
如果想進(jìn)一步優(yōu)化wordpress的性能可以使用nginx的fastcgi_cache,當(dāng)使用fastcgi_cache配置需要在編譯nginx時(shí)加上ngx_cache_purge模塊以及使用wordpress的緩存插件等等

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊15 分享