Adding Sub-Sites with Nginx

Create sub-sites or prefixed WordPress blogs quickly & easily. Just create an A record, add a vhost file & symlink and restart Nginx.
This is very similar to adding a domain, which is detailed here and cheat-sheeted here, but not quite the same, so I’ve cranked out this simple guide.
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Take your virtual private server from zero to hero
.. from blank box to cute-as server ..
with this easy-to-follow copy/paste guide.
22+ parts with video, here’s the index.
This tutorial presumes you have already set up a site or blog with the VPS Bible, and therefore have already enabled FastCGI and, for WordPress, the required FURL & caching scripts. If not, check out the VPS Bible index. Otherwise, just substitute “mySubSite” for yours and “mydomain.com” for your_domain.tld throughout this how-to.
Create an A or AAAA Record
If we do this first, by the time everything else is done the new DNS record should have registered and we’ll be ready to go.
Go to your web host’s DNS manager and create an A record, adding the following:-
| Hostname | IP | TTL (Time to Live) |
|---|---|---|
| mySubSite | the IP you use for mydomain.com | shortest option |
Save the record and exit the DNS manager. It’ll take a short while for the new setting to propagate. At my VPS, Linode, it’s minutes not hours. Yours? Dunno, but probably no longer than an hour or two.
Add Site Directories
At the terminal, type:-
So we have a nicely independent site or blog and, if you like, you can add users to maintain the sub-sites, giving them SFTP access to only that site and so on.
Create a Temp Homepage (optional)
You don’t have to bother with this section, but it can be useful.
Type:-
.. hit return and paste:-
Add Virtual Host (vhost) with FastCGI, FURL Support & Optional WordPress Caching
Type this:-
Hit return and paste this, with the five domain substitutions:-
Option: If you don’t use WordPress with this sub-site, delete the following lines from the above:-
Option: If you do want WordPress, and want both pretty permalinks and WP Super Caching support, leave the above, as is.
Option: If you do want WordPress, and want pretty permalinks but not WP Super Caching, swap this:-
.. for this :-
Save the file.
Create the Symlink and Restart Nginx
Paste this into the terminal:-
And reboot the web server by typing ..
.. Or if you followed Set Up Unmanaged VPS (4 Newbies) – Part 7: Edit bashrc for User-Friendly Linux, plus System Updates, just type:-
Upload your sub-domain files and go check it. If you’re moving an existing site, you should read this for a hassle-free relocation.
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Take your virtual private server from zero to hero
with this easy-to-follow copy/paste guide.
“My local PC runs Windows” Show me for Linux
“My local PC runs Linux” Show me for Windows
22+ parts with video, here’s the index ..
-
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Introducing vpsBible’s how-to guide for setting up a super-charged unmanaged VPS featuring Ubuntu and Nginx.
-
VPS (Virtual Private Server) vs Shared vs Dedicated
Before getting stuck in, let’s compare the web host types in detail and weigh up the differences between managed & unmanaged VPS.
-
Set Up a VPS Linux Distribution
Opening a VPS hosting account, we’ll choose, configure & launch a Linux server ‘distribution’.
-
Set Up Command Line Interface (CLI) using PuTTY
Now we’ve got a server to play with, we’ll connect to it, using the ’ssh’ protocol for a super-secure link.
-
Create a Linux User & Set Permissions
Initially you’ve logged into your remote Linux machine as ‘root’. We’ll add you as a user now, with root or SuperUser permissions.
-
Encrypt Data with OpenSSH & Auto-Login with PuTTY
Now we can use ‘authentication keys’ to shore up our connection while simplifying login to an automated, password-free yet secure process.
-
Harden the Secure Shell (SSH) & Create a Firewall
The final security step: galvanizing the OpenSSH protocol and setting up an ‘iptables’ firewall. Now the server is rock ruddy solid.
-
Edit bashrc for User-Friendly Linux, plus System Updates
We use the terminal a whole lot so let’s cut ourselves a break and create some command shortcuts, then update the server.
-
PHP5, MySQL and Xcache (for Platforms like WordPress)
We have our foundation, let’s lay some bricks: PHP for server-side web applications, Xcache to speed things up & MySQL for databases.
-
Add a Domain Zone to Your VPS
To make your server aware of yourDomain.com you’ll need a few ‘DNS’ records. Damn this is simple I’m practically asleep!
-
Prepare Linux Server for Email with Postfix
In order to send and receive email from our web applications we’ll install some software and tweak the ‘RDNS’ record.
-
Nginx (better than Apache) Web Server
OK I woke up .. let’s install this supersonic web server, tweaking its file structure & adding default configuration files.
-
Setup FileZilla for Secure FTP (SFTP)
There’s FTP, and then there’s ‘Secure FTP’. We’ll set up FileZilla using SFTP – and those authentication keys – for secure file transfers.
-
Serve Multiple Sites & Blogs with Virtual Hosts
We want a website folder structure, some permissions, some site-specific configuration files and, hey, we’ll hook up ‘FastCGI’.
-
Adding Sub-Domains with Nginx
Need a sub-domain? Here’s how to add www.sub.domain.com with an ‘A record’ and a configuration file. (I’ll allow you to skip this bit.)
-
Integrate A CMS Like WordPress, WP MU, Drupal etc
For those of you wanting to use a specific content framework, such as a CMS, blogging or forum software, pop in here and we’ll sort that out.
-
Configure phpMyAdmin for Nginx to Maintain MySQL
Rather than have to crunch databases via the command line, we can make life easier by adding this splendid tool to manage them.
-
Google Apps for Domain-Specific Email
GA’s free Standard Edition for catchall webmail – POP-ping or IMAP-ped to your desktop client – saves precious server resources for your webs.
-
Moving Day! How to Move Your Blog or Site
Nearly there. Here’s the web site or blog migration guide, relocating to your VPS with minimal or no downtime.
-
Appendix 1a: Nginx Control Panel
You’re migrating shared-to-VPS and want a GUI like cPanel? No you don’t, not after you read this! What’s more, you don’t need one either.
-
Appendix 1b: Nginx Control Panel Workarounds
For every control panel module there’s an equivalent terminal command. They’re all linked from here so, hey, no excuses!
-
Appendix 2: Add Web Sites Nginx Cheatsheet
Once you’ve set up your first site, adding more gets easier. Especially when you can refer to this. (Let’s face it, I’m just too good to you.)
Got a Question? Want to Comment?
This site has no comments system. We've got a better system!
Please use the link at the top of the post and goto this topic's forum thread:-
- to help build community
- for a superior knowledge base
- to keep info in one place, not diluted between forum & comments.
For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.
Handy info from these comments is in the process of being ported to the forum and attributed to the original author.
If you think this idea sucks, let me know.
Thank you.




















eyecool September 4th, 2009 at 8:40 am
Hey Guvnr, is there an easy was to do domain mapping on nginx and mu? You know, something like ILoveTheGuv.com points to luvguv.yoursite.com or MeetTheGuvnr points to meetme.yoursite.com.
Thanks for the great guides.
Don September 10th, 2009 at 3:58 pm
Really useful guide, thanks :-]
the_guv September 16th, 2009 at 8:33 pm
@eyecool .. big tx.
you need Redirect Web Pages with Nginx Rewrite Rule. oh, mu you say, hmmn, not sure that’ll work actually. no, course it won’t!
er, anyone? (i’m only just getting into wp mu)
@Don .. lovely dovely, thank you.