wordpress多站点模式可以被应用在多种方式上。其中最常用的是在”子目录”模式或者”二级域名”模式上。
Nginx提供了两种特殊的指令:”x-accel-redirect”和”map”,使用这两个指令可以使得wordpress多站点的网络服务实现伪静态功能。
配置中shouce.ren修改为自己的站点域名。
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 shouce.ren ; root /var/www/shouce.ren/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/shouce.ren/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; } #此处可以继续添加伪静态规则 }
配置中shouce.ren修改为自己的站点域名。
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 shouce.ren *.shouce.ren ; root /var/www/shouce.ren/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/shouce.ren/htdocs/wp-content/blogs.dir; access_log off; log_not_found off; expires max; } #此处可以继续添加伪静态规则 }
备注