How To Setup Custom Domain For Google App Engine

August 1, 2017
Serving pages from your own domain instead of the default *.appspot.com

Prerequisites

Assuming you already owned or puchased a domain (Why I use Namecheap).

Add custom domain to App Engine

Visit Google Cloud Platform - Console.

Make sure the correct project is selected at the top bar.

Goto App Engine > Settings > Custom Domains (or search Custom Domains at the top search bar).

Click Add a custom domain

Add Custom Domain

If you already have a verified domain, just select it from the drop down list and click Continue.
Else, select Verfiy a new domain, enter the domain and clicm Verfify. You shall be redirected to Webmaster Central to verify your site ownership.

You shall be asked about domain and subdomains mapping, with the followng mapping created by default (meaning App Engine will handle incoming requests using the following domain and subdomains)
www.mydomain.com
mydomain.com

The subdomain mapping will redirect naked domain mydomain.com -> www.mydomain.com. If you plan to host on a subdomain (e.g. test.mydomain.com), such mapping is not necessary. Click on Submit mappings and click Continue

You need to change the DNS reords of your domain (A, AAAA, CNAME) as per the instruction. (Note: if you are using a different subdomain other than www, configure the CNAME for the subdomain instead of www)

Configure DNS

Once done, you should see the following custom domain mapping setup.

Custom Domain Mapping

You can test your custom domain now. (if it doesn’t work, make the the DNS records have been propagated; simplest method is to ping the domain name to make sure ghs.googlehosted.com is shown on the first line)

Redirect domains

You will notice now your website could be accessed using 3 different urls
http://www.mydomain.com
http://mydomain.com
https://myprojectid.appspot.com

If you would like to redirect all requests from different domain into a single domain, refer to Redirect Domain on Google App Engine

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.