Mapping Custom Domains

App Engine allows applications to be served via a custom domain, such as example.com, instead of the default appspot.com address. You can create a domain mapping for your App Engine app so that it uses a custom domain. By default, when you map your custom domain to your app, App Engine issues a managed certificate for SSL for HTTPS connections. For more information on using SSL with your custom domain, including how to use your own SSL certificates, see Securing your custom domains with SSL.

Use this page to learn how to create a domain mapping for your app that is running on App Engine.

Before you begin

  • Purchase a new domain, unless you already have one that you want to use. You can use any domain name registrar, including Google Domains.

  • If you choose to use the gcloud tool commands:

    1. Install and initialize the Cloud SDK:

      Download and install

    2. Install the beta component by running:

      gcloud components install beta
      
  • If you choose to use the Admin API, see the prerequisite information in Accessing the Admin API.

Adding a custom domain for your application

To add a custom domain for your App Engine app:

  1. Verify that you are the owner of your domain through Webmaster Central:

    console
    1. In the Google Cloud Platform Console, go to App Engine > Settings > Custom Domains:

      Go to the custom domains page

    2. Click Add a custom domain to display the Add a new custom domain form:

      Add a custom domain

    3. In the Select the domain you want to use section, enter the name of the domain that you want to use, for example example.com, and then click Continue to open a new tab to the Webmaster Central page.
      1. Use Webmaster Central to verify ownership of your domain.

        Important: Verifying domain ownership by using a CNAME record is the preferred option for App Engine. If you choose to use a TXT record, you must avoid configuring your domain's DNS with a CNAME record because the CNAME record overrides the TXT record and causes your domain to appear unverified.

        If the verification methods for your domain do not offer the CNAME record option, you can select Other as your domain provider and then choose Add a CNAME record:

        1. Click Alternate methods and then Domain name provider.
        2. In the menu, select Other.
        3. In the Having trouble section, click Add a CNAME record and then following the instructions to verify ownership of your domain.

          Remember: It might take a minute before your CNAME is set at your domain registrar.

      2. Return to the Add new custom domain form in the Cloud Platform Console.
    gcloud
    1. Run the following gcloud domains command to open the Webmaster Central page:

      gcloud domains verify DOMAIN

      where DOMAIN is the domain for which you want to verify ownership.

      Example:

      gcloud domains verify example.com
    2. Use Webmaster Central to verify ownership of your domain.

      Important: Verifying domain ownership by using a CNAME record is the preferred option for App Engine. If you choose to use a TXT record, you must avoid configuring your domain's DNS with a CNAME record because the CNAME record overrides the TXT record and causes your domain to appear unverified.

      If the verification methods for your domain do not offer the CNAME record option, you can select Other as your domain provider and then choose Add a CNAME record:

      1. Click Alternate methods and then Domain name provider.
      2. In the menu, select Other.
      3. In the Having trouble section, click Add a CNAME record and then following the instructions to verify ownership of your domain.

        Remember: It might take a minute before your CNAME is set at your domain registrar.

      Example
      To add the following CNAME record to your domain's DNS configuration:
      CNAME Label / Host: a1b2c3d4e5.example.com.
      CNAME Destination / Target: gv-abcdefghijk.dv.googlehosted.com
      You map the Label / Host and Destination / Target values to the corresponding fields of your domain's DNS configuration. For example, in Google Domains, you set the CNAME as follows:
      NAMETYPETTLDATA
      a1b2c3d4e5CNAME1hgv-abcdefghijk.dv.googlehosted.com.

      For more information about adding a CNAME record, including domain specific instructions, see the support page.

  2. Ensure that your domain has been verified:

    console

    If your domain is not already listed, click Refresh domains.

    gcloud

    Run the following gcloud domains command to list your verified domains:

    gcloud domains list-user-verified

  3. If you need to delegate the ownership of your domain to other users or service accounts, you can add permission through the Webmaster Central page:

    1. Opening the following address in your web browser:

      https://www.google.com/webmasters/verification/home

    2. Under Properties, click the domain for which you want to add a user or service account.

    3. Scroll down to the Verified owners list, click Add an owner, and then enter a Google Account email address or service account ID.

      To view a list of your service accounts, open the Service Accounts page in the Cloud Platform Console:

      Go to Service Accounts page

  4. After you verify ownership of your domain, you can map that domain to your App Engine app:

    console

    Continue to the next step of the Add new custom domain form to select the domain that you want to map to your App Engine app:

    1. Specify the domain and subdomains that you want to map. The naked domain and www subdomain are pre-populated in the form.
      • A naked domain, such as example.com, maps to http://example.com.
      • A subdomain, such as www, maps to http://www.example.com.
    2. Click Save mappings to create the desired mapping.
    3. In the final step of the Add new custom domain form, note the resource records that are listed, including their type and canonical name (CNAME), because you need to add these details to the DNS configuration of your domain.

      In the example below, CNAME is one of the types listed, and ghs.googlehosted.com is its canonical name.

      Add a custom domain
    gcloud

    Run the following gcloud beta app domain-mappings command to map your domain to your App Engine app:

    gcloud beta app domain-mappings create DOMAIN
    • where DOMAIN is the domain that you want to map to your App Engine app., such as *.example.com.
    • Use gcloud beta app domain-mappings instead of gcloud app domain-mappings to have a managed certificate for SSL automatically provisioned for your app.
    • If you get an error, try using quotes around your domain, such as '*.example.com'.

      Example:

      gcloud beta app domain-mappings create '*.example.com'
    • Note the resource records that are now listed, including their type and canonical name (CNAME), because you need to add these details to the DNS configuration of your domain.

  5. Add the resource records that you receive to the DNS configuration of your domain registrar:

    1. Log in to your account at your domain registrar and then open the DNS configuration page.

    2. Locate the host records section of your domain's configuration page and then add each of the resource records that you received when you mapped your domain to your App Engine app.

      Typically, you list the host name along with the canonical name as the address. For example, if you registered a Google Domain, then one of the records that you add to your DNS configuration is the www host name along with the ghs.googlehosted.com address. Alternatively, to specify a naked domain, you would instead use @ with the ghs.googlehosted.com address.

      For more information about mapping your domain, see the following Using subdomains and Wildcard mappings sections.

    3. Save your changes in the DNS configuration page of your domain's account. It can take a while for these changes to take effect.

  6. Test for success by browsing to your app via its new domain URL, for example www.example.com.

Using subdomains

If you set up a wildcard subdomain mapping for your custom domain, then your application serves requests for any subdomain that matches.

  • If the user browses a domain that matches an application version name or service name, the application serves that version.
  • If the user browses a domain that matches a service name, the application serves that service.
  • There is a limit of 20 managed SSL certificates per week for each base domain. If you encounter the limit, App Engine keeps trying to issue managed certificates until all requests have been fulfilled.

Wildcard mappings

You can use wildcards to map subdomains at any level, starting at third-level subdomains. For example, if your domain is example.com and you enter text in the web address field:

  • Entering * maps all subdomains of example.com to your app.
  • Entering *.private maps all subdomains of private.example.com to your app.
  • Entering *.nichol.sharks.nhl maps all subdomains of nichol.sharks.nhl.example.com to your app.
  • Entering *.excogitate.system maps all subdomains of excogitate.system.example.com to your app.

Wildcard mappings will work with your services in App Engine.

If you use G Suite with other subdomains on your domain, such as sites and mail, those mappings have higher priority and are matched first, before any wildcard mapping takes place. In addition, if you have other App Engine apps mapped to other subdomains, those mappings also have higher priority than any wildcard mapping.

Some DNS providers might not work with wildcard subdomain mapping. In particular, a DNS provider must permit wildcards in CNAME host entries.

The above wildcard routing rules also apply to URLs that contain components for services, versions, and instances, following the service routing rules for the App Engine.

What's next

Secure your custom domains with SSL.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine standard environment for Go