WordPress中开启多站点支持及Nginx的重写规则配置

2019-10-17 19:38:50丽君

wordpress多站二级域名重写规则:
配置中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;
 }
 
 #此处可以继续添加伪静态规则
}

备注

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