Configure Domains and Subdomains in your VPS Running NginX
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 www.example.com to point to the VPS web server you have setup using this guide. So that you can type in your domain name (www.example.com) 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:
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.
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 “mail.example.com”. 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:
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/example.com/, /var/www/example2.com/ etc. and place the corresponding website files in those directories and then tell NginX to serve example.com requests from example.com directory and example2.com requests from example2.com 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 store.example.com:
Create the configuration file for subdomain store.example.com and enable it by creating a link to it:
Now type ‘i’ for entering editing mode and use the similar configuration available here. You just need to change the server_name to store.example.com 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.
Now the second configuration is for the new domain example2.com:
Create the configuration file for the new domain:
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 www.example2.com and set the directory addresses to the addresses for example2.com 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 example2.com.
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.