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.
Wow, you've got a real mess on your hands.
Overall the nginx configuration looks good. The only thing that struck me on first reading as being possibly "wrong" was the
try_files
statement. In my production WordPress multisite, I have:It's not necessary to append the args, as WordPress picks them up from
REQUEST_URI
when it is available, (almost always) andPATH_INFO
when they aren't present in the query string.Yes, I'm aware that the statement you are using is what's "recommended" on the WordPress site. Of course it's also a wiki that anybody can edit, so it has to be taken with a grain of salt, just like Wikipedia.
Found the problem. It wasn't the rewrite rules, though Michael Hampton definitely set me in the right direction.
For some reason, the wp-config.php file had two very important lines for Multisite configuration commented out: PATH_CURRENT_SITE and BLOG_ID_CURRENT_SITE.
As soon as I fixed that, everything started working perfectly, and our site is now blazing fast. I guess the real question is: how the h*** did this work all this time?
That's it here. Thanks for watching!