Nginx + Wordpress Multisite 3.4.2 + subdirectories + static pages and permalinks
- by UrkoM
I am trying to setup Wordpress Multisite, using subdirectories, with Nginx, php5-fpm, APC, and Batcache.
As many other people, I am getting stuck in the rewrite rules for permalinks.
I have followed these two guides, which seem to be as official as you can get:
http://evansolomon.me/notes/faster-wordpress-multisite-nginx-batcache/
http://codex.wordpress.org/Nginx#WordPress_Multisite_Subdirectory_rules
It is partially working:
http://blog.ssis.edu.vn works.
http://blog.ssis.edu.vn/umasse/ works.
But other permalinks, like these two to a post or to a static page, don't work:
http://blog.ssis.edu.vn/umasse/2008/12/12/hello-world-2/
http://blog.ssis.edu.vn/umasse/sample-page/
They either take you to a 404 error, or to some other blog!
Here is my configuration:
server {
    listen       80 default_server;
    server_name  blog.ssis.edu.vn;
    root         /var/www;
    access_log   /var/log/nginx/blog-access.log;
    error_log    /var/log/nginx/blog-error.log;
    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    # Add trailing slash to */username requests
    rewrite ^/[_0-9a-zA-Z-]+$ $scheme://$host$uri/ permanent;
    # Directives to send expires headers and turn off 404 error logging.
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
    }
    # this prevents hidden files (beginning with a period) from being served
      location ~ /\.          { access_log off; log_not_found off; deny all; }
    # Pass uploaded files to wp-includes/ms-files.php.
    rewrite /files/$ /index.php last;
    if ($uri !~ wp-content/plugins) {
        rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
    }
    # Rewrite multisite '.../wp-.*' and '.../*.php'.
    if (!-e $request_filename) {
        rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
        rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
        rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    }
    location ~ \.php$ {
    # Forbid PHP on upload dirs
        if ($uri ~ "uploads") {
            return 403;
        }
        client_max_body_size 25M;
        try_files      $uri =404;
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }
}
Any ideas are welcome! Have I done something wrong?
I have disabled Batcache to see if it makes any difference, but still no go.