WordPress中開啟多站點支持及Nginx的重寫規(guī)則配置
在Wordpress3.0及以上版本可以直接使用多站點,它可以:
1、只安裝一個Wordpress程序即可創(chuàng)建多個wordpress站點,可以是子域名也可以是子目錄。
2、可以有獨立的博客后臺,獨立的博客地址。
3、管理員可設(shè)置開放哪些主題給站點使用。
4、管理員可配置插件給每個站點使用。
5、多個站點之間共用“用戶數(shù)據(jù)庫表”,也就是表 wp_usermeta 和 wp_users,其他的為獨立數(shù)據(jù)庫表。
WordPress多站點的配置方法:
1、首先,備份網(wǎng)站的數(shù)據(jù)庫,以防出現(xiàn)意外時恢復(一般可忽略)。
2、打開WordPress的根目錄下的wp-config.php文件,在
require_once(ABSPATH . 'wp-settings.php');
前面加上以下代碼:
define('WP_ALLOW_MULTISITE',true);
3、進入WordPress后臺,”工具”-> 點擊”配置網(wǎng)絡”
ps:如果您要使用二級域名的形式,可以到“設(shè)置”->“常規(guī)”里面,把站點地址(URL)的www.去掉。

4、點擊安裝后,按照提示做好相關(guān)的配置
5、配置好,再次進入后臺,在頭部將出現(xiàn)“我的站點”->“管理網(wǎng)絡”的選項菜單,接下來您可以管理或者創(chuàng)建站點,也可以開啟主題或者插件給其他站點使用。

6、如果要給站點綁定其他域名,可以安裝 WordPress MU Domain Mapping 插件。
nginx多站點rewrite(重寫)規(guī)則
wordpress多站點模式可以被應用在多種方式上。其中最常用的是在”子目錄”模式或者”二級域名”模式上。
Nginx提供了兩種特殊的指令:”x-accel-redirect”和”map”,使用這兩個指令可以使得wordpress多站點的網(wǎng)絡服務實現(xiàn)偽靜態(tài)功能。
wordpress多站點使用子目錄重寫規(guī)則:
配置中jb51.net修改為自己的站點域名。
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;
#多站點配置
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ī)則
}
wordpress多站二級域名重寫規(guī)則:
配置中jb51.net修改為自己的站點域名。
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”部分可以應用于小站點。大站點的多站點應用可以使用 nginx-helper wordpress插件 。
如果想進一步優(yōu)化wordpress的性能可以使用Nginx的fastcgi_cache,當使用fastcgi_cache配置需要在編譯nginx時加上ngx_cache_purge模塊以及使用wordpress的緩存插件等等
相關(guān)文章
Nginx服務器中瀏覽器本地緩存和虛擬機的相關(guān)設(shè)置
這篇文章主要介紹了Nginx服務器中瀏覽器本地緩存和虛擬機的相關(guān)設(shè)置,是Nginx服務器搭建過程中的基本配置,需要的朋友可以參考下2015-08-08
詳解Nginx虛擬主機配置中server_name的具體寫法
這篇文章主要介紹了Nginx虛擬主機配置中server_name的具體寫法,server_name服務器名是虛擬主機中必須配置的重要參數(shù),需要的朋友可以參考下2016-03-03

