In this article, we will learn How to point a domain to Google Cloud Compute Engine VM instance? We are using Ubuntu 18.04 LTS as an operating system on our VM Instance.
We cover following points in this article
1. Use Cloud DNS to create a zone for our domain.
2. Update Name servers for our domain.
3. Configure our Server and Apache to handle requests for our domain.
We are assuming you have a Google Cloud Compute Engine VM instance with apache installed in it. For the demo, we are using a VM Instance with Ubuntu 18.04 LTS and Apache. Check this article to create a new Ubuntu 18.04 VM Instance with Apache, PHP, and MySQL.
First, we need to create a zone for our domain. Visit http://cloud.google.com open Google Cloud Console and then Cloud DNS. On the Cloud DNS page, create a new zone for our domain. For the new Zone provide the following information
Zone name: Provide a unique DNS Zone name. Must be unique in a project.
DNS name: enter your domain here
DNSSEC: DNSSEC or DNS Security is a feature which prevents attackers from manipulating or poisoning the responses to DNS requests.
Description (Optional): Provide a short description for the zone. It is optional, but as a best practice always provides a brief description.
A new DNS Zone is created. Next, we need to create an "A" record set. The "A" record set helps us to point our domain to VM instance. Before creating a new "A" record set you need your VM instance IP Address. You can find the VM Instance IP address on Compute Engine -> VM Instances page.
Add another record set of type "CNAME". The CNAME record set helps you to map www.yourdomain.com to yourdomain.com.
Zone for our domain is ready. Next, we need to update the name servers for our domain.
Google provide 4 name servers. Add all 4 entries on your domain control panel. Name server changes may take some time. If on visiting on your domain it is not reflected correctly, wait for at least 24 Hours.
If you create another DNS zone for some other domain. You followed the same steps mentioned above. And visit the domain after all the changes you will get the same page. Why?
By default, Apache points all requests to "var/www/html" directory contain the Apache default page. We didn't create any site in Apache. So for all requests, we are getting the same page. We need to change this behavior. We want domain-specific directory so we can post different contents for different websites. For this, we need to configure Apache to handle the request based on domain name or Sites.
Following are the steps to add a new site in apache:
sudo cp 000-default.conf vlemon.ooo.conf
sudo nano vlemonn.ooo.conf
We need to edit the highlighted lines with
Save the file using Ctrl+O and close the file using Ctrl+X
Open “/var/www/” directory
Create vlemon.oo and html directory
sudo mkdir vlemon.ooo
sudo mkdir html
sudo nano index.html
In nano editor add a welcome text “Hello vLemonn!”. Ignore HTML for the time being. Save the file by pressing Ctrl+O followed by Ctrl+X.
We are done with Apache configuration. Next, we need to enable our new website and then restart apache services to apply new configurations.
sudo a2ensite vlemon.ooo
sudo service apache2 restart
Finally, our domain is mapped and Apache is ready to display our website.
Similarly, You can add other domains.
Please login to post your valuable comments.
Get the latest vLemonn news first