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.
Using custom domains in the following regions might add noticeable latency to responses:
- us-west2
- us-east4
- northamerica-northeast1
- southamerica-east1
- europe-west2
- europe-west3
- asia-south1
- asia-northeast1
- australia-southeast1
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
gcloudtool commands:Install and initialize the Cloud SDK:
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:
Verify that you are the owner of your domain through Webmaster Central:
console -
In the Google Cloud Platform Console, go to App Engine > Settings > Custom Domains:
-
Click Add a custom domain to display the Add a new custom domain form:
-
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.-
Use Webmaster Central to verify ownership of your domain.
Important: Verifying domain ownership by using a
CNAMErecord is the preferred option for App Engine. If you choose to use aTXTrecord, you must avoid configuring your domain's DNS with aCNAMErecord because theCNAMErecord overrides theTXTrecord and causes your domain to appear unverified.If the verification methods for your domain do not offer the
CNAMErecord option, you can select Other as your domain provider and then choose Add a CNAME record:- Click Alternate methods and then Domain name provider.
- In the menu, select Other.
-
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.
- Return to the Add new custom domain form in the GCP Console.
-
gcloud -
Run the following
gcloud domainscommand to open the Webmaster Central page:gcloud domains verify DOMAIN
where
DOMAINis the domain for which you want to verify ownership.Example:
gcloud domains verify example.com
-
Use Webmaster Central to verify ownership of your domain.
Important: Verifying domain ownership by using a
CNAMErecord is the preferred option for App Engine. If you choose to use aTXTrecord, you must avoid configuring your domain's DNS with aCNAMErecord because theCNAMErecord overrides theTXTrecord and causes your domain to appear unverified.If the verification methods for your domain do not offer the
CNAMErecord option, you can select Other as your domain provider and then choose Add a CNAME record:- Click Alternate methods and then Domain name provider.
- In the menu, select Other.
-
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
CNAMErecord to your domain's DNS configuration:CNAME Label / Host: a1b2c3d4e5.example.com. CNAME Destination / Target: gv-abcdefghijk.dv.googlehosted.com
You map theLabel / HostandDestination / Targetvalues to the corresponding fields of your domain's DNS configuration. For example, in Google Domains, you set the CNAME as follows:NAME TYPE TTL DATA a1b2c3d4e5 CNAME 1h gv-abcdefghijk.dv.googlehosted.com.
For more information about adding a
CNAMErecord, including domain specific instructions, see the support page.
-
Ensure that your domain has been verified, otherwise you will not be able to proceed with the following steps. Note that only verified domains will be displayed.
console If your domain is not already listed, click Refresh domains.
gcloud Run the following
gcloud domainscommand to list your verified domains:gcloud domains list-user-verified
API To programmatically list your verified domains, see the apps.authorizedDomains.list method in the Admin API.
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:
Opening the following address in your web browser:
Under Properties, click the domain for which you want to add a user or service account.
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 GCP Console:
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:
-
Specify the domain and subdomains that you want to map. The naked
domain and
wwwsubdomain are pre-populated in the form.-
A naked domain, such as
example.com, maps tohttp://example.com. -
A subdomain, such as
www, maps tohttp://www.example.com.
-
A naked domain, such as
- Click Save mappings to create the desired mapping.
-
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,
CNAMEis one of the types listed, andghs.googlehosted.comis its canonical name.
gcloud Run the following
gcloud app domain-mappingscommand to map your domain to your App Engine app:gcloud app domain-mappings create DOMAIN
-
where
DOMAINis the domain that you want to map to your App Engine app, such as*.example.com. -
If you get an error, try using quotes around your domain, such as
'*.example.com'.Example:
gcloud 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.
API To programmatically map your domain to your App Engine app, see the
app.domainMappings.createmethod in the Admin API.After your domain is mapped to your App Engine app, use the
apps.domainMappings.listmethod to list your resource records.-
Specify the domain and subdomains that you want to map. The naked
domain and
Add the resource records that you receive to the DNS configuration of your domain registrar:
Log in to your account at your domain registrar and then open the DNS configuration page.
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
wwwhost name along with theghs.googlehosted.comaddress. To specify a naked domain, you would instead use@with theghs.googlehosted.comaddress.If you are migrating from another provider, make sure all DNS records point to your App Engine app.
For more information about mapping your domain, see the following Using subdomains and Wildcard mappings sections.
Save your changes in the DNS configuration page of your domain's account. It can take a while for these changes to take effect.
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 matching subdomain.
- 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
*.example.commaps all subdomains ofexample.comto your app. - Entering
*.private.example.commaps all subdomains ofprivate.example.comto your app. - Entering
*.nichol.sharks.nhl.example.commaps all subdomains ofnichol.sharks.nhl.example.comto your app. - Entering
*.excogitate.system.example.commaps all subdomains ofexcogitate.system.example.comto your app.
You can use wildcard mappings with services in App Engine by using the
dispatch.yaml
file to define request routing to specific services.
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.
Wildcard routing rules apply to URLs that contain components for services, versions, and instances, following the service routing rules for App Engine.


