Here’s a quick tip if you’re on Nginx with multiple WordPress installations in a sub-folder of your main WordPress and you want pretty permalinks to work correctly.

The problem is this: We’re running WPMU on our TLD but have mockups in a subdirectory (e.g. TLD.com/mymockups). In that folder, there are multiple folders that each contain a copy of WordPress.

With Nginx’s default settings, you’ll get errors and odd behavior if you try to enable pretty permalinks on the subdirectory WP installs while concurrently running pretty permalinks on your TLD’s WP ( which is why you’re here in the first place ). The solution to getting everyone to behave nicely is a custom entry for each of your subdirectories in the corresponding .conf file.

Here’s what I have:

  • TLD.com (WPMU)
  • TLD.com/subdir/sitea (WP)
  • TLD.com/subdir/siteb (WP)

Go to your Nginx configuration file for the TLD.com, and find the part where Nginx starts handing locations. You want to process these requests before looking for files served from your TLD.com, so add a location block that looks like this:

server {

  server_name yourdomain.com www.yourdomain.com;

  root /path/to/main/wordpress;

  access_log /var/log/nginx/yourdomain.com-access.log;
  error_log /var/log/nginx/yourdomain.com-error.log;

  include /etc/nginx/conf.d/restrictions.conf;
  include /etc/nginx/conf.d/wordpress.conf;

  location /subdir/anotherdomain.com/ {
    try_files $uri $uri/ /subdir/anotherdomain.com/index.php?$args;
  }

  location /subdir/anotherdomainagain.com/ {
    try_files $uri $uri/ /subdir/anotherdomainagain.com/index.php?$args;
  }
}

The above example assumes that you have two folders, anotherdomain.com and anotherdomainagain.com, sitting in a subdirectory that exists alongside your WPMU installation (at yourdomain.com). Here’s what happens: First, your WPMU root is established in this server instance. Every time someone visits your domain, it will look for the files to serve in that folder. Since your other WordPress installations are in sub-folders, you need to tell this server block to listen for people accessing those locations, that way the server delivers the appropriate WP files.

Once you’ve modified your .conf file, be sure to run the following command to reload Nginx:

service nginx reload

If you’re having trouble or have some questions, leave a comment.

Jesse Lawson

I write science fiction and research multi-agent systems for cognition and intelligence simulation. More importantly, I love breakfast burritos.

lawsonry lawsonry


Published