Welcome! Log In Create A New Profile


nginx, wordpress multisite with subdomains, blogs.dir alternative.

Posted by plutocrat 
nginx, wordpress multisite with subdomains, blogs.dir alternative.
July 07, 2014 06:10AM
There has previously been some discussion of how the configs of Wordpress Multisite on nginx.org and wordpress.org are both not working correctly for recent versions of Wordpress past version 3.5. eg.


I'd like to focus down on one element of this. So in previous versions of Wordpress, uploaded files are referenced in a directory called blogs.dir. I don't have access to an old installation, but I gather uploaded files are handled by this nginx config rule.

location ~ ^/files/(.*)$ {
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;

In newer installations of WP multisite, the directory structure is different. A single install will look like this

And when you move to a multi install they become this

... here the root site will retain the original WP single site URL, whereas additional sites will have /sites/ and the site ID in the URL, in this case 2.

My installation is a multi site, using separate domains rather than subdirectories. I understand about the mapping of domain names to WP blog ID in the site config i.e.
map $http_host $blogid {
default -999;
originaldomain.com 1;
second.originaldomain.com 2;
seconddomain.com 2;

I've been trying, therefore, to correctly direct browser clients to the correct URL when presented with the following:
So, any time it gets a request in /wp-content/uploads, it needs to needs to either re-write the URL, or preferably just interpret it as:

Here's my attempt. It seems to work. Does this seem right? Feel free to use it in the nginx/wpmu documentation if it seems good.

location ~ ^/wp-content/uploads/(.*)$ {
try_files /wp-content/uploads/sites/$blogid/$1 /wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;

I don't really understand the ms-files.php bit. Does that seem OK for what I'm doing?

Second question. This is the second item which references blogs.dir. I don't understand what this is doing. Can someone suggest a re-write which would fit the new directory structure. Original is:

#avoid php readfile()
location ^~ /blogs.dir {
alias /var/www/example.com/htdocs/wp-content/blogs.dir ;
access_log off; log_not_found off; expires max;
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 59
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready