Home » nginx WordPress Multisite subdomain configuration example

nginx WordPress Multisite subdomain configuration example

This is a simple tutorial for how to setup a WordPress Multisite subdomain configuration within nginx. This setup will require a plugin provided by rtCamp called nginx-helper that will provide a map of blog ids that you can include in the configuration example below.  Again, this is an nginx WordPress Multisite subdomain configuration example, so this may need to be altered to your needs. Subdomain configurations allow you to map different domains to the same WordPress Multisite so they can all be managed within the same admin panel.

As always I am open to any suggestions on how to make this better, and the following config has some stuff that’s specific to this site. One thing that’s always good to have is fastcgi passing through the local unix: protocol so there’s no network overhead. If you need help doing so, add a comment to this post and I’ll send you some links to other articles I’ve written on how to do that.

First let’s follow the instructions that WordPress has on setting up a network:

http://codex.wordpress.org/Create_A_Network

Now let’s follow the tutorial rtCamp has on their site on how to setup domain mapping (note: I use a different directory structure than they do, so my tutorial will reference my directory structure instead. Change that according to your needs):

https://rtcamp.com/wordpress-nginx/tutorials/multisite/domain-mappinng/

Once that’s all setup, let’s install rtCamp’s nginx-helper plugin. I typically install this through the Network Admin screen by just typing in “nginx-helper” in the add new plugin box.

Now that we have that plugin installed, you’ll want to change the permissions on the directories it needs to access, which will be based on your user/group setup that you have. The settings screen on the nginx-helper plugin will give you error messages when you check the box to enable mapping for your blog IDs. Try to enable that and modify your permissions as needed until the plugin can write your map file. You’ll copy/paste that into line 8 in the example config below (change the directories as needed):

After this you can safely test and reload nginx as you normally would:

If the test comes back successful, then go ahead and safely reload nginx:

I wrote this post pretty quickly so I could have a reference to this config for myself later. If this nginx WordPress Multisite subdomain configuration example doesn’t work for you, or there’s some extra steps that you’d suggest I include here then feel free to post a comment and I’ll modify it so it is more helpful to people that are less familiar with this process.

4 comments on “nginx WordPress Multisite subdomain configuration example

  1. saikat on

    I have this site hosted on hostgator. I was trying to set up multisite option but it is showing 404 not found/nginx 1.2.4. while trying to open dashboard of new site (subdomain). I think this is happening as I modified .htaccess as per WP.org guidance which has considered apache. Now after a lot of search I found your post and installed rtcamp nginx plugin but it is showing the error ‘Can’t write on map file.’ There is a recommendation ‘Nginx Map path to include in nginx settings (recommended)’ as well. I am confused at this stage. Can you guide me what should be done so that I can access new sites?

    Reply
    • Jeff Hays on

      Hey saikat,

      So the directory to your nginx-helper plugin needs to be writeable by nginx in order for it to create the map file. You can run this command on the nginx-helper plugin directory to make it writeable:

      chown -R yourftpuser:nginx /www/yoursite.com/public/wp-content/plugins/nginx-helper && chmod -R g+w /www/yoursite.com/public/wp-content/plugins/nginx-helper

      (but change yourftpuser to the FTP user you use to install plugins and change /www/yoursite.com/public/wp-content/plugins/nginx-helper to the path to the nginx-helper plugin directory. After you do that, the directory should be writeable by nginx and you can click save in the nginx-helper settings for the map file to be created. Once your map file is created on the server, you’ll want to include that map file at the top of your virtual host config for that site like you see in the config example above. Also notice the #Multisite config inside the server block in the example above; you’ll want to copy both of those into your config.

      After you’re done with that you can test your config to make sure there’s no errors and reload the config file without taking nginx down:

      nginx -t
      nginx -s reload

      If you still have issues, feel free to post another comment and include your entire virtual host file and any errors from your logs and we’ll try to help troubleshoot.

      Reply
  2. saikat on

    Hi Jeff,
    Thanks for your time to answer my comment.
    I am new to coding and might sound silly!
    I was unable to understand how ‘run this command on the nginx-helper plugin directory’ as you mentioned. I checked though cpanel but there was no option to run the command on the mentioned directory.

    Reply
    • Jeff Hays on

      Hey saikat,

      If you’re using cpanel then you just need to navigate to that nginx-helper plugin directory and make sure that it’s owned by your FTP user (whether that’s saikat or whatever your FTP username will be) and that the group is nginx.

      Then you just need to make sure that the group has write access. I’m not exactly sure how you do this with your interface, but that will give nginx the ability to write to that directory to create the map file you need.

      Reply

Leave a Reply

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