How to Create Sub Domain in Google Cloud Compute Engine

How to Create Sub Domain in Google Cloud Compute Engine

In our previous article on Google Cloud Platform we covered below points

 In this article we are going to learn about How to add a Sub Domain. Before start we are assuming, you already have a working Compute Engine VM Instance. In this article we are going to use Ubuntu 17.10. If you are looking for any other OS. Please refer below articles.

For creating a subdomain in Ubuntu 17.10 follow below steps.

Let’s first modify our server to handle request for new sub domain. Open terminal and navigate to “/etc/apache2/sites-available/”. Execute below command in terminal

cd /etc/apache2/sites-available/

In this directory we have default conf file 000-default.conf we are using it as a base for our new sub domains. Execute below command to create a Copy of 000-default.conf file.

sudo cp 000-default.conf subdomain.vlemonn.in.conf

Now it’s time to edit newly created file in nano editor

sudo nano subdomain.vlemonn.in.conf

Below image show the default file structure. We are going to modify highlighted lines.

In the above file, we are going to add below lines.

ServerName subdomain.vlemonn.in
ServerAlias www.subdomain.vlemonn.in
ServerAdmin [email protected]
DocumentRoot /var/www/subdomain.vlemonn.in/html

Now we need to create subdomain.vlemonn.in/html folder in /var/www/ folder. Execute below commands line by line to create directory

cd /var/www/
sudo mkdir subdomain.vlemonn.in
sudo mkdir html

Now our folder is ready. Let’s create an index.html file to handle HTTP request. 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.

Now it enables configuration and then restarts the server. Execute below command line by line.

sudo a2ensite subdomain.vlemonn.in
sudo service apache2 restart

Finally, our server is ready to handle HTTP request. What next? Now we need a DNS entries to handle subdomain request. For this follow below steps for cloud.google.com console page.

For creating DNS records or entries we need to open Network Services -> Cloud DNS under NETWORKING section in the left menu.

 

Add a recordset.

DNS name : subdomain.vlemonn.in

Record Type: A

IPv4: <Server IP>

Don’t modify any other fields. Click on Create button to save the changes.

Create another record set to handle www requests for our subdomain

DNS name : www.subdomain.vlemonn.in

Record Type: A

IPv4: <Server IP>

Don’t modify any other fields. Click on Create button to save the changes.

Let’s try to visit our new subdomain “subdomain.vlemonn.in”. If everything is fine you are able to check our page.

You may also like below articles.

 

Finally, check this video for all above steps

2 Comments
Leave A Comment

Please login to post your valuable comments.

  • ...
    Reply

    Mayank Sanghvi

    Hi, I hope you found the solution for your issue. If you edited the configuration file then check for any issue in the config file.

  • ...
    Reply

    Trần Mạnh

    Hi, tks for this but i get a problem i don't know how to fixi[email protected]:/var/www/hihi.vesinhbonnuoc.net$ sudo service apache2 restartJob for apache2.service failed because the control process exited with error code.See "systemctl status apache2.service" and "journalctl -xe" for details.Plz help me!

Join the newsletter

Get the latest vLemonn news first

share