Welcome! Log In Create A New Profile

Advanced

Complex Multi-site configuration

Posted by plutocrat 
Complex Multi-site configuration
December 13, 2011 03:17AM
Hi all,
Been lurking for a few months, and have managed to figure out how to migrate a bunch of sites on Wordpress, Wordpress MultiUser, and Joomla over to nginx. I've also set up nginx as a proxy in front of apache. So I'm not a complete novice. However this particular configuration has got me puzzled.

The site in question is a Joomla site running in the root of the webserver ie. domain.com/
Wordpress Multisite is running in a subdirectory, ie domain.com/blog
All individual blogs are running off there. ie domain.com/blog/john , domain.com/blog/peter

So, obviously I've been looking around the internet for solutions. I've looked at the following sites, and have tried ALL the configuration options suggested at all the sites.
- http://wiki.nginx.org/WordPress
- http://codex.wordpress.org/Nginx#WordPress_Multisite_Subdirectory_rules
- http://stackoverflow.com/questions/2278277/rewrite-rules-for-wordpress-3-0-multi-site-for-nginx
- http://wordpress.org/support/topic/nginx-php-fpm-php-apc-wordpress-multisite-subdirectory-wp-super-cache
- http://dmitriy.us/blog/4/nginx-rewrite-rules-for-chyrp-blog/

Those are just the ones I have open right now. I must have tried 30 different configurations over the last two days. The Joomla site works fine. My problem is with the Wordpress /blog subdirectory. At the BEST case, the main/root blog will load fine. ie. domain.com/blog works OK. When I try to load a sub-blog the worst that happens (depending on what config I'm using) is that I get a 404 message (in fact the _Joomla_ 404 page). On other configurations I can get the sub-blog page (eg domain.com/blog/peter ) to load the text, but all images/ css files are missing. This is because the server is looking for them in (for example)
domain.com/blog/peter/wp-content/blah/blah/file.css
instead of
domain.com/blog/wp-content/blah/blah/file.css

So ... in terms of general approach, what I've been trying is this

server {
location / {
Joomla configuration
}
location /blog {
Wordpress configuration
}
Fast cgi configuration.
}
But I can't hit the magic config. Once again I've set up Wordpress and Joomla separately, and these are fine, but its this complicated Nested config, with multisite wp, which is giving me problems.

I'll post the server config in the next post.
Re: Complex Multi-site configuration
December 13, 2011 03:33AM
This config gives me a Joomla 404 error page
=========================================
## domain.com server has a Joomla install, with wordpress in the /blog/ subdirectory
##
server {
listen 80;

# Answer to both www and non-www requests.
server_name www.domain.com domain.com;

# File locations
root /home/serveradmin/domains/domain.com/public_html;
access_log /home/serveradmin/domains/domain.com/logs/access.log;
error_log /home/serveradmin/domains/domain.com/logs/error.log;
error_page 404 /404.html;

# Index pages
index index.php index.html index.htm;

# Fixes 502 Bad Gateway error. (upstream sent too big header)
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}

# Wordpress Config in /blog directory
#####################
location /blog/ {
try_files $uri $uri/ @blog;
}

location @blog {
if (!-e $request_filename) {
rewrite ^/blog/.*/wp-content/(.*)$ /blog/wp-content/$1 last;
}
}
################

# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}

location ~ .*.php$ {
include /etc/nginx/fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}

location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}

}
Re: Complex Multi-site configuration
December 15, 2011 05:39AM
Latest try ... same config for the location / stanza (because that's working OK) , and replacing the location /blog bit with the following code adapted from here. http://wordpress.org/support/topic/nginx-php-fpm-php-apc-wordpress-multisite-subdirectory-wp-super-cache

Result ... still just get the Joomla (ie not even wordpress) 404 page when I try to access any sub-blogs. The main blog page still works, but that's all.

# Wordpress Config in /blog directory
#####################
location /blog/ {
try_files $uri $uri/ /blog/index.php?$args;

# Add trailing slash to */wp-admin requests.
rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

# Pass uploaded files to wp-includes/ms-files.php.
rewrite /blog/files/$ /blog/index.php last;

if ($uri !~ wp-content/plugins) {
rewrite /blog/files/(.+)$ /blog/wp-includes/ms-files.php?file=$1 last;
}

# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite ^/blog/[_0-9a-zA-Z-]+(/blog/wp-.*) $1 last;
rewrite ^/blog/[_0-9a-zA-Z-]+(/blog/.*\.php)$ $1 last;
}
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense. http://forum.nginx.org/read.php?2,88845,page=3
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}


} ####### End of /blog block #########

Been working on this for seven days now ... tearing my hair out.
Re: Complex Multi-site configuration
December 16, 2011 02:05AM
OK, back to basics. I've stripped everything out and am starting from first principles.

# Wordpress Config in /blog directory
#####################
location /blog {
try_files $uri $uri/ /blog/index.php;
}


This _single_ configuration line in the Wordpress subdirectory block gets me all the pages on the root blog working correctly. (ie domain.com/blog )
It also allows me to see the text of each sub-blog, but not the images / css files etc, which have the wrong URL still
ie. I can see domain.com/blog/simon
Images are still getting the wrong URL for eg. the site is trying to display
http://domain.com/blog/simon/wp-content/themes/mytheme/images/logo.png
when the correct URL is
http://domain.com/blog/wp-content/themes/mytheme/images/logo.png

I'm working on adding the necessary re-writes now.
Re: Complex Multi-site configuration
December 16, 2011 03:11AM
# Rewrite to strip the blogname out of URLs.
rewrite ^/blog/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /blog/$2 break;

Adding this line gives me my css and theme-related images back. Interestingly, using any of the
if ( -e $request_filename ) or if ( !-e $request_filename) constructs doesn't work.

Next problem is trying to get the embedded / uploaded images to show up. I've been trying versions of the ms-files rule, but even though the rewrite is generating the correct URL, ms-files.php is throwing a 404.

One thing that has helped me enormously is adding increased logging to the server for debugging. Specifically

error_log /home/serveradmin/domains/domain.com/logs/error.log notice;
... at the top of the config file and
rewrite_log on;
... in the location /blog stanza.
Re: Complex Multi-site configuration
December 16, 2011 03:45AM
So I've added this rule.

# Rewrite to load image files
rewrite ^/blog/.*/files/(.*) /blog/wp-includes/ms-files.php?file=$1 break;

This appears in the logs, so I know its been matched, and its generating the correct URL out.
2011/12/16 08:21:14 [notice] 4977#0: *18 "^/blog/.*/files/(.*)" matches "/blog/simon/files/2008/02/p1000287.thumbnail.JPG"
2011/12/16 08:21:14 [notice] 4977#0: *18 rewritten data: "/blog/wp-includes/ms-files.php", args: "file=2008/02/p1000287.thumbnail.JPG"

Which creates this URL:
http://domain.com/blog/wp-includes/ms-files.php?file=2008/02/p1000287.thumbnail.JPG

However that gives me a 404 error.

But I know the file exists. If I look on the server in

/blog/wp-includes/blog.dir/files/104/2008/02/

(I happen to know what dir belongs to that user: 104) ... The file is there, and has the correct permissions.

If I type
http://domain.com/blog/wp-content/blogs.dir/104/files/2008/02/p1000287.thumbnail.JPG
I can retrieve the file.

So it seems that the redirect is good, but just that ms-files.php isn't working correctly.

Frustrating ...
Re: Complex Multi-site configuration
January 04, 2012 04:18AM
Still trying to figure this one out. The following configuration was working, so I thought.

location /blog {
# debug
# rewrite_log on;
try_files $uri $uri/ @wordpress;
}

location @wordpress {
rewrite ^/blog/([_0-9a-zA-Z-]+/)?files/(.+) /blog/wp-includes/ms-files.php?file=$2 last;
rewrite ^/blog/([_0-9a-zA-Z-]+/)?wp-admin$ /blog/$1wp-admin/ permanent;
rewrite ^/blog/[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) /blog/$1 last;
rewrite ^/blog/[_0-9a-zA-Z-]+/(.*\.php)?$ /blog/$1 last;
rewrite /blog/.* /blog/index.php last;
}

Admin pages worked, and all the various blog contents work fine. eg
/blog/user1/post/

However, it turns out that the individual users can't login and adminster their own blogs. We found this out after putting the site live unfortunately. So now URLs like
/blog/user1/wp-admin/widgets.php
Give us the "No input file selected" error, which means that the file can't be found.

Debugging the rewrites seems to indicate that the correct URLs are being written.

Entering the re-written URL ie /blog/wp-admin/widgets.php gives the correct WP response (permission errror)

Stuck.
Re: Complex Multi-site configuration
January 06, 2012 05:24AM
I gave up on this one in the end. I just moved all the blogs to a separate domain ... blog.domain.com and used a standard Wordpress nginx config. All works well (although the Wordpress migration was a pain).

I put some redirects in from domain.com/blog to blog.domain.com and all traffic is now going to the new domain.

If anyone ever figures out the Wordpress Multisite in a Subdirectory configuration, I'd still be interested in seeing how its done. I wasted several days on this one.
Re: Complex Multi-site configuration
July 08, 2014 06:24AM
Ever get the feeling you're talking to yourself ...
Re: Complex Multi-site configuration
July 08, 2014 07:24AM
Every day :)

But to keep it short and simple, don't do sub folder inside a domain, register *.domain.com, add a DNS for this wildcard and host unlimited (wp)xyz.domain.com sites.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Complex Multi-site configuration
July 08, 2014 08:35PM
Haha,
Thanks for the support itpp2021. I actually opened up a new thread recently about a different problem (actually a solution to a problem I found and thought I'd share). While I was logged in, I looked for old threads and found this one. Basically 9 posts from me with no other takers, and I couldn't resist a sarcastic comment!

For the record, in the end I did give up and moved the blogs from a WPMU subdirectory setup to a WPMU subdomain setup, which I recorded in the final post before the thread stopped. Well it used to be the final post ... :-)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
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