In this post I will show how to configure NGINX to host multiple domains on a VPS
I will be using
Digital Ocean (for hosting, but any hosting provider like Linode, Dreamhost, etc can be used)
I will show how to host 3 domain names. Lets say they are:
First we will setup our DNS records for each of the domains. Here is how they look.
I have shown how to deploy a Ruby on Rails app in my previous post - Deploy Ruby on Rails 4 Application on Ubuntu 12.04 With Nginx and Passenger
I have deployed 3 apps for each domain and they are in the below paths:
On the server, Nginx has a default configuration file at /etc/nginx/sites-available
and a symlink to this file at /etc/nginx/sites-enabled
We will remove the symlink to the default file (which is equal to disabling the default configuration) and create 3 configuration files for the 3 domains
Now lets create symlinks for these files in /etc/nginx/sites-enabled
We will have the below configuration in these files
To verify if all the configurations are correct, run sudo nginx -t
That is all we have to do.
Open a browser and check for domain1.com, domain2.com, domain3.com. They should load the sites.
If anything is not working you can do a couple of things to see what is wrong
- Verify if all the configurations are correct by running sudo nginx -t
- Check NGINX log files at /var/log/nginx/