Nginx 上配置 WordPress Mu 的重写规则

wordpressmu

WordPress Mu 可以看作是一款多用户版的 WordPress,可以方便架设自己的 BSP,像 blogbus.com,yo2.cn 做的那样。 后台和 WP 差不多,多了一个 Site Admin 用来管理整个 blog, 其他部分和独立的 WP 大同小异。最方便的是 WPMU 和 WP 的部分插件和主题可以通用,基于 WP 丰富的主题和插件,可以很好的应用到 WPMU 上。这样,节约了重新定制主题和寻找插件的时间和资源。

首先需要安装和配置好 Nginx+PHP5+Mysql+FastCGI,然后从官方网站下载 WPMU,安装完毕后打开 nginx.conf,配置 Nginx 以支持 WordPress MU 的 rewrite rules。注意:需要把下面的 vpsee.com 和路径换成你自己的域名和路径;如果不用 WP SuperCache 插件可以把相关部分注释掉。

server {
    listen 80;
    server_name vpsee.com *.vpsee.com; #requires a type wildcard dns entry
    access_log /www/vpsee.com/logs/access.log;
    error_log /www/vpsee.com/logs/error.log;
    error_page 500 502 503 504 /error/50x.html; #your error files
    client_max_body_size 16M; #for file uploads

    # WordPress MU的rewrite rules
    location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|
        doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
        root /www/vpsee.com;
        rewrite ^/.*(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|
            gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|
            rtf|js))$ $1 last;
        rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|
            rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|
            js))$ /wp-content/blogs.php?file=$1 last;
        expires 30d;
        break;
    }

    location / {
        root /www/vpsee.com;
        index index.php index.html;

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

        # 支持WordPress Super Cache 插件的 rewrite rules
        if (-f $request_filename) {
            break;
        }

        set $supercache_file '';
        set $supercache_uri $request_uri;

        if ($request_method = POST) {
            set $supercache_uri '';
        }

        # Using pretty permalinks, so bypass the cache for any query string
        if ($query_string) {
            set $supercache_uri '';
        }

        if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
            set $supercache_uri '';
        }

        # if we haven't bypassed the cache, specify our supercache file
        if ($supercache_uri ~ ^(.+)$) {
            set $supercache_file 
                /wp-content/cache/supercache/$http_host/$1index.html;
        }

        # only rewrite to the supercache file if it actually exists
        if (-f $document_root$supercache_file) {
            rewrite ^(.*)$ $supercache_file break;
        }

        # all other requests go to WordPress
        if (!-e $request_filename) {
            rewrite . /index.php last;
        }
    }

    # 最后是php fastcgi
    location ~ \.php$ {
        rewrite ^/.*(/wp-.*/.*.php)$ $1;
        fastcgi_pass 127.0.0.1:2345;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /www/vpsee.com$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}

评论 (4 Comments)

  1. 你这个网站的模块我喜欢,可以介绍给我吗?

  2. 哪个模块?你是说 “模板/主题/theme” 吗?你可以看看这个 http://wordpress.org/extend/themes/plainscape,风格差不多~~

  3. 谢谢!我说的是整站的主题!

  4. 晕,相逢恨晚。
    以前头破血流就为了搞这多站点的玩意,没想到时隔一年。在您这里遇见了。
    感谢阿!

发表评论