Welcome! Log In Create A New Profile

Advanced

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.

http://forum.nginx.org/read.php?2,249743,249780#msg-249780

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
/wp-content/uploads/YYYY/MM/filename.jpg

And when you move to a multi install they become this
/wp-content/uploads/sites/2/YYYY/MM/filename.jpg

... 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:
http://seconddomain.com/wp-content/uploads/2014/07/picture.jpg
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:
http://seconddomain.com/wp-content/uploads/sites/2/2014/07/picture.jpg

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 {
internal;
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: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready