找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1962|回复: 0

[分享] wordpress nginx多站点rewrite(重写)规则

[复制链接]
发表于 2016-1-14 13:45:01 | 显示全部楼层 |阅读模式 来自 河南省南阳市

wordpress多站点模式可以被应用在多种方式上。其中最常用的是在"子目录"模式或者"二级域名"模式上。
Nginx提供了两种特殊的指令:"x-accel-redirect"和"map",使用这两个指令可以使得wordpress多站点的网络服务实现伪静态功能。
wordpress多站点模式可以被应用在多种方式上。其中最常用的是在"子目录"模式或者"二级域名"模式上。Nginx提供了两种特殊的指 令:"x-accel-redirect"和"map",使用这两个指令可以使得wordpress多站点的网络服务实现伪静态功能。
wordpress多站点使用子目录重写规则
配置中54ux.com修改为自己的站点域名。
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;
#多站点配置
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;
}
#此处可以继续添加伪静态规则
}
wordpress多站二级域名重写规则
配置中54ux.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 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;
}
#此处可以继续添加伪静态规则
}
备注
"map"部分可以应用于小站点。大站点的多站点应用可以使用 nginx-helper wordpress插件 。
如果想进一步优化wordpress的性能可以使用Nginx的fastcgi_cache,当使用fastcgi_cache配置需要在编译nginx时加上ngx_cache_purge模块以及使用wordpress的缓存插件等等

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-4 08:56 , Processed in 0.038822 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表