Published on Oct 1, 2011

Configure Domains and Subdomains in your VPS Running NginX

Setup Your Domain to Serve Pages from Your VPS Server

Setup Your Domain to Serve Pages from Your VPS Server

As you’ve seen so far, we were testing our server pages using the IP-Address instead of the domain name. You might be wondering how to setup your domain say to point to the VPS web server you have setup using this guide. So that you can type in your domain name ( in your browser to access the hosted content and website located in your server. This article will provide you the details of how to do that with Linode and NginX. If you are on other platforms, no worries, the process is almost similar in any other platforms.

At-first you need to add a DNS zone in your VPS server. As we are using linode VPS servers, the process is very easy using the Linode DNS Manager. You’ll find a DNS manager in almost all the popular VPS service provider control panels. Using Linode as an example, just go to the adminpanel/controlpanel provided by the website from where you’ve bought your domain name, then find the settings page where it says “Name Servers” and set the name servers to the Linode name servers as Follows:


Now allow up to 24 hours for DNS changes to be reflected throughout the Internet, although it may happen much faster. You can use the whois utility from a shell prompt to see if your domain’s record has been updated with linode nameservers. Once your domain is reporting those nameservers as authoritative, you may log into the Linode Manager and click the “DNS Manager” tab. You’ll see an empty zone list:

DNS Zone Setup using Linode DNS Manager

DNS Zone Setup using Linode DNS Manager

Now Click “Add a new domain zone” to begin setting up your domain in our DNS. Enter the domain name and your SOA email address (use the administrative contact email address for your domain) and click “Add a Master Zone” to proceed.

Add a Master Zone in DNS Manager

Add a Master Zone in DNS Manager

Several DNS records will be automatically created for your domain. These include a default entry for your domain, A records for “www” and “mail”, and an MX record directing mail delivery to “”. You may now add more records as needed. If you wanted to host a store on your site as a subdomain, you might create an A record for it by clicking on “Add a new A Record” and filling in the required fields:

Add a Subdomain (A Record) in DNS Manager

Add a Subdomain (A Record) in DNS Manager

You can also add another new domain if you want in similar way. Just set the name server addresses in your domain control panel, then add A Records and Put the ip address of your VPS server. You can use the same VPS server to host several sites with different domain/subdomain names. To do so just add the necessary domain and subdomain records as shown here above. Then you need to tell the web server program (NginX in this case, if you use Apache, the procedure will be similar)  for each domain/subdomain to have their own directories as their web root.

For example you can use separate directories for each domain like /var/www/, /var/www/ etc. and place the corresponding website files in those directories and then tell NginX to serve requests from directory and requests from directory. To do so, you need to create some more configuration files for NginX. Here I’m giving you two example configuration files, the first one is for subdomain

Create the configuration file for subdomain and enable it by creating a link to it:

sudo vi /etc/nginx/sites-available/

Now type ‘i’ for entering editing mode and use the similar configuration available here. You just need to change the server_name to and change all the directory locations in the settings to the assigned directory for this subdomain.

Now save the file by pressing “ESC” then type :x and hit enter. Then create a link to this file to enable the configuration for the subdomain.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Now the second configuration is for the new domain

Create the configuration file for the new domain:

sudo vi /etc/nginx/sites-available/

Now type ‘i’ for entering editing mode and refer to the configuration file here to set the values properly. As like the subdomain, you only need to change the server_name to and set the directory addresses to the addresses for in your server.

Now save the file by pressing “ESC” then type :x and hit enter. Then create a link to this file to enable the configuration for the new domain

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

You can see these configurations are almost similar to the initial configuration we did for setting up the NginX web server in our VPS. Only the changes are in the directory addresses for NginX to serve files from. Remember that you need to create those directories with read permissions for the www-data user so that NginX can read the contents of those directories.

Articles in this Step by Step VPS Setup Guide

Getting Started with VPS – The Beginners Tutorial
Introductory concepts on web servers and virtual private servers. Introducing you to the world wide web from a technical point of view.

Shared Hosting, VPS, Dedicated and Cloud Servers
Comparing the popular server hosting solutions. Basic understanding of shared, dedicated, vps and cloud servers.

Deploy a Linux VPS Server using Linode
Tutorial on deploying your linux distribution in your VPS server and setting up hostname and initial configurations

Setup NginX Web Server (Not Apache!) on Ubuntu 10.04
Analyzing why NginX web server is better for you instead of the mostly used Apache. Demonstration on how to setup and configure NginX on Ubuntu server.

Enable HTTPS (HTTP+SSL) in NginX Web Server
Tutorial on enabling secure http connections for NginX web server. Demonstrating how to self sign your SSL certificate for the VPS server.

NginX Password Protect Web Directory
Helping you to protect specific web directories with passwords for restricting access to administration section or important private files that need to be accessed through the web.

Setup PHP-FPM with APC on Ubuntu 10.04 for Faster Performance
Installing and Configuring PHP5 with Fast CGI Process Manager along with the excellent op-code cache solution APC for faster and optimized PHP backend.

Setup MySQL with PHPMyAdmin on Ubuntu 10.04
Setting up MySQL database server and configuring for better performance in low memory environment. Also setup a web based database management front-end named PHPMyAdmin.

Configure Domains and Subdomains in your VPS Running NginX
Tutorial on DNS setup for adding additional domains and subdomains. Also configuring NginX for handling each domains/subdomains.

Domain Emails for Free Using Google Apps
Setup domain specific email addresses without installing any email server in your VPS. Google Apps seems to be a better solution in this regard.

Author: Masum
Tags: , , ,

1 Comment + Add Comment

  • Amit Bhatia

    June 27, 2012 at 8:48 pm

    Well… most of the instructions work but there are many errors. Being a newbie I had no idea from where to start. Your instructions looked good so I made it a starting point till the time I kept on running into problems like installing php5-fpm on 10.04 ubuntu. I was unable to do that. Finally I upgraded my linode to version 12.04 and followed this guide
    Well, I was up and running in a day.

    This guide needs updation.

Leave a comment