Rewrite rules for Multisite using subdomains
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 example.com *.example.com ;
root /var/www/example.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/example.com/htdocs/wp-content/blogs.dir;
access_log off; log_not_found off; expires max;
}
#add some rules for static content expiry-headers here
}
Note NGINX WordPress Shared Hosting Model - AnsiPress can be used. AnsiPress is created based on Ansible playbooks and support NGINX, PHP7, MariaDB, Google PageSpeed installation as well as automate WordPress installations/setup. For wordpress-nginx based sites management, EasyEngine can be used. EasyEngine (ee) is python based command line control panel to setup NGINX server on Ubuntu and Debian Linux distribution for HTML, PHP, MySQL, HHVM, PageSpeed and WordPress sites. map section can be completed manually for small sites. On large multisite network nginx-helper wordpress plugin can be used. Further performance gain is possible by using NGINX’s fastcgi_cache. When using fastcgi_cache, compile NGINX with ngx_cache_purge module and add a wordpress-plugin which performs automatic cache purge on events e.g. a wordpress post/page is edited. NGINX Cache Controller WordPress plugin provides some functions of controlling NGINX proxy server cache. NGINX Mobile Theme WordPress plugin allows you to switch theme according to the User Agent on the NGINX reverse proxy.