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

wordpress多站点模式可以被应用在多种方式上。其中最常用的是在”子目录”模式或者”二级域名”模式上。
Nginx提供了两种特殊的指令:”x-accel-redirect”和”map”,使用这两个指令可以使得wordpress多站点的网络服务实现伪静态功能。

wordpress多站点使用子目录重写规则

配置中shouce.ren修改为自己的站点域名。

map$uri$blogname{ ~^(?P/[^/]+/)files/(.*)$blogpath; } map$blogname$blogid{ default-999; #Ref:https://wordpress.org/extend/plugins/nginx-helper/ #include/var/www/wordpress/wp-content/plugins/nginx-helper/map.conf; } server{ server_nameshouce.ren; root/var/www/shouce.ren/htdocs; indexindex.php; #多站点配置 location~^(/[^/]+/)?files/(.+){ try_files/wp-content/blogs.dir/$blogid/files/$2/wp-includes/ms-files.php?file=$2; access_logoff;log_not_foundoff;expiresmax; } #avoidphpreadfile() location^~/blogs.dir{ internal; alias/var/www/shouce.ren/htdocs/wp-content/blogs.dir; access_logoff;log_not_foundoff;expiresmax; } if(!-e$request_filename){ rewrite/wp-admin$$scheme://$host$uri/permanent; rewrite^(/[^/]+)?(/wp-.*)$2last; rewrite^(/[^/]+)?(/.*.php)$2last; } location/{ try_files$uri$uri//index.php?$args; } location~.php${ try_files$uri=404; includefastcgi_params; fastcgi_passphp; } #此处可以继续添加伪静态规则 } wordpress多站二级域名重写规则

配置中shouce.ren修改为自己的站点域名。

map$http_host$blogid{ default-999; #Ref:https://wordpress.org/extend/plugins/nginx-helper/ #include/var/www/wordpress/wp-content/plugins/nginx-helper/map.conf; } server{ server_nameshouce.ren*.shouce.ren; root/var/www/shouce.ren/htdocs; indexindex.php; location/{ try_files$uri$uri//index.php?$args; } location~.php${ try_files$uri=404; includefastcgi_params; fastcgi_passphp; } #WPMUFiles location~^/files/(.*)${ try_files/wp-content/blogs.dir/$blogid/$uri/wp-includes/ms-files.php?file=$1; access_logoff;log_not_foundoff;expiresmax; } #WPMUx-sendfiletoavoidphpreadfile() location^~/blogs.dir{ internal; alias/var/www/shouce.ren/htdocs/wp-content/blogs.dir; access_logoff;log_not_foundoff;expiresmax; } #此处可以继续添加伪静态规则 }

备注

“map”部分可以应用于小站点。大站点的多站点应用可以使用nginx-helperwordpress插件。 如果想进一步优化wordpress的性能可以使用Nginx的fastcgi_cache,当使用fastcgi_cache配置需要在编译nginx时加上ngx_cache_purge模块以及使用wordpress的缓存插件等等

标签: nginx wordpress rewrite ng res write nx 重写 pr ss gin word gi pre ite te dp

wordpress数据库优化的方法(简洁操作版)

wordpress实现301的方法

上述就是wordpress nginx多站点rewrite(重写)规则分享!的全部内容,如果对大家有所用处且需要了解更多关于wordpresscms模板学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/wordpresscmst/913125.html

(0)
上一篇 2021年10月31日
下一篇 2021年10月31日

精彩推荐