nginx and WordPress MU

WARNING: DO NOT USE IT. IT IS OUTDATED. WILL BE UPDATED IF SOMEONE REQUESTS FOR IT (POST A COMMENT).

(tl;dr: use Apache if you’re lazy. I also suspect using lighttpd is as easy)

The guide on codex fails. The guide on codex is now fixed (by me, lol).

So does the guide here. Or here (too much noise).

The last (two) link(s) can yield result though… but dead once I try to use plugins (presumably thanks to its filename lytebox.js.php).

Took me two freakin hours to solve the problem: the (sample’s) regex is gay. Seriously. Below is the config which have been trimmed and might be inefficient (or slower) compared to last two links. But at least it works. I’m using subfolder mode. Subdomain one shouldn’t be much different.

server {
listen 80;
server_name megafail.co.cc;
root /usr/local/www/megafail.co.cc;
index index.php;

location / {
rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?/?(/wp-.*) $1 last;
rewrite ^(.+)$ /index.php?q=$1 last;
}
}

location ~ .php$ {
if (!-e $request_filename) {
rewrite ^.+?/?(/wp-.*.php)$ $1 last;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_intercept_errors  on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME  /usr/local/www/megafail.co.cc$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}

What’s the difference?

here’s the sample from first link:

  rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1
  if (!-e $request_filename) {
   rewrite ^.+/?(/wp-.*) $1 last;
   rewrite ^.+/?(/.*.php)$ $1 last;
   rewrite ^(.+)$ /index.php?q=$1 last;
  }

If you see closely, the difference is located at rewrite’s regex which I mentioned before. Mine has more ‘?’, or in this case, uses lazy plus instead of plus which means that the pattern matching stops on first occurence (or something like that).

This time’s nginx challenge is much more difficult compared last time’s challenge… ;_;

Update: apparently the solution is already on nginx mailing list (and it’s before I joined the mailing list so I didn’t find any result in my mail. LOL).

More or less the same, the difference being that everything is located at server block instead of location block and doesn’t use /?.

rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite  ^.+?(/wp-.*)     $1          last;
rewrite  ^.+?(/.*.php)$  $1          last;
rewrite  ^                /index.php  last;
}

Update 2: I decided to edit the codex page manually. Now everyone should be happy. 🙂

6 thoughts on “nginx and WordPress MU

  1. Pingback: things to look at (December 18th - December 31st) | stimulant - changing things around. . .

  2. Pingback: Заметки архитектора

  3. Hi,

    A couple of months ago, I tried to configure nginx + WordPress MU and create blogs over various domains, but I could not make it work.
    So with your solution this is possible?

Leave a Reply

Your email address will not be published. Required fields are marked *