How to map a domain with Google Cloud Compute Engine Ubuntu 18 VM Instance

How to map a domain with Google Cloud Compute Engine Ubuntu 18 VM Instance

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.

Step1 Create a Cloud DNS Zone

First, we need to create a zone for our domain. Visit 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 to

Zone for our domain is ready. Next, we need to update the name servers for our domain. 

Step 2 Update Name Servers for 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.

Step 3 Configure Apache

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:

  • Open SSH. In SSH execute command to open sites-available directory 

cd /etc/apache2/sites-available/

  • List down available files using “ls” command. We have two available files in it 000-default.conf and default-ssl.conf. We will use 000-default.conf file as a reference for our new website.
  • Create a copy of 000-default.conf with name Execute command

sudo cp 000-default.conf

  • The domain or website specific file is created successfully. Next, we need to edit it using nano editor. Execute command to open nano editor with file.

sudo nano

We need to edit the highlighted lines with

  • ServerName
  • ServerAlias
  • ServerAdmin [email protected]
  • DocumentRoot /var/www/

Save the file using Ctrl+O and close the file using Ctrl+X

  • Next, we need to create “/var/www/” directory.

Open “/var/www/” directory

cd /var/www/

Create vlemon.oo and html directory

sudo mkdir


sudo mkdir html

cd html

  • Now our folder is ready. Let’s create an index.html file for testing. Execute below command to open nano editor.

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

sudo service apache2 restart

Finally, our domain is mapped and Apache is ready to display our website.

Similarly, You can add other domains.

Leave A Comment

Please login to post your valuable comments.

Join the newsletter

Get the latest vLemonn news first