Wordpress教程丨多站点伪静态设置

Wordpress教程丨多站点伪静态设置,第1张

Wordpress网站如果运用到多站点操作,那么我们就可以在二级域名上运用到Nginx,实现主题站的多站点伪静态功能状态,Nginx提供了两种特殊的指令:”x-accel-redirect”和”map”

Wordpress教程丨多站点伪静态设置,第2张



1.wordpress多站点使用子目录重写规则,配置中baisheng.com修改为自己的站点域名:

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 baisheng999.com ;


root /var/www/baisheng999.com/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/baisheng999.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;

}


#此处可以继续添加伪静态规则

}



2.Wordpress多站二级域名重写规则配置中baisheng999.com修改为自己的站点域名。

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 baisheng999.com *.baisheng999.com ;


root /var/www/baisheng999.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/baisheng999.com/htdocs/wp-content/blogs.dir;

access_log off; log_not_found off; expires max;

}


#此处可以继续添加伪静态规则

}

备注
 
“map”部分可以应用于小站点。大站点的多站点应用可以使用 nginx-helper wordpress插件 ,如果想进一步优化wordpress的性能可以使用Nginx的fastcgi_cache,当使用fastcgi_cache配置需要在编译nginx时加上ngx_cache_purge模块以及使用wordpress的缓存插件等等
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » Wordpress教程丨多站点伪静态设置

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情