nginx下配置wordpress多站點(diǎn)rewrite規(guī)則

2013-04-08 20:53:08來源:chinaz作者:

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

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

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

wordpress多站點(diǎn)使用子目錄重寫規(guī)則

配置中54ux.com修改為自己的站點(diǎn)域名。

map $uri $blogname{

~^(?P/[^/]+/)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 54ux.com ;

root /var/www/54ux.com/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/54ux.com/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多站二級(jí)域名重寫規(guī)則

配置中54ux.com修改為自己的站點(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 54ux.com *.54ux.com ;

root /var/www/54ux.com/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/54ux.com/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的緩存插件等等。

關(guān)鍵詞:nginxwordpressrewrite

贊助商鏈接: