This topic describes how to bind a custom domain name to a web application in the Function Compute console.

Prerequisites

  • An HTTP function is created.

    Requests sent from a custom domain name can trigger only HTTP functions.

  • An Internet Content Provider (ICP) filing for the custom domain name is applied for in the Alibaba Cloud ICP Filing system or Alibaba Cloud is added as a service provider to the ICP filing information of the custom domain name. For more information, see ICP filing application overview.
  • A canonical domain name (CNAME) is configured for your custom domain name. If you use Alibaba Cloud DNS, see the specific procedure in Quick Start.

Procedure

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Custom Domain.
  4. Click Create Domain.
  5. In the Add Custom Domain panel, set the parameters and click OK.
    create-domain
    Parameter Description
    Custom Domain Name Enter a custom domain name that has obtained an ICP filing in the Alibaba Cloud ICP Filing system or whose ICP filing information includes Alibaba Cloud as a service provider.
    CDN Acceleration Turn on or turn off CDN Acceleration based on your requirements.
    Protocol Select a protocol that are supported by the custom domain name from the Protocol drop-down list. Valid values:
    • HTTP: The custom domain name can be accessed only over HTTP.
    • HTTP,HTTPS: The custom domain name can be accessed over HTTP and HTTPS.
      To allow users to access your custom domain name over HTTPS, you must set the Certificate Type parameter.
      • If you select Alibaba Cloud Security Certificate as Certificate Type, you must select an Alibaba Cloud security certificate from the Certificate Name drop-down list.
      • If you select Custom Certificate as Certificate Type, you must enter a certificate name in the Certificate Name field, the certificate in the Privacy-Enhanced Mail (PEM) encoding format in the Certificate field, and the private key in the PEM encoding format in the Private Key field. Alternatively, you can click manage and upload certificates to go to the SSL Certificates Service console and upload your certificate. Make sure that the certificate you want to upload does not exceed 20 KB in size, and the private key does not exceed 4 KB in size. If you do not have an available certificate, you can click issue certificates to issue a certificate.
    Routing Config
    Notice You can configure custom domain names only for functions that have HTTP triggers. Create an HTTP trigger function before you configure routes.
    Configure the relationship between paths and functions. This way, requests from different paths can trigger different functions. You must set the following fields:
    • Path: the path from which a request can trigger the specified function in the specified service.
    • Service Name: the name of the service to which the specified function belongs.
    • Function Name: the name of the function triggered by a request from the specified path.
    • Version/Alias: the version or alias of the specified service to which the function triggered by a request from the specified path belongs.

    For more information, see Routing rules.

    Note You can configure multiple routes as needed.

Routing rules

You must configure the relationship between paths and functions when you bind a custom domain name. This way, requests from different paths can trigger different functions. Function Compute supports exact match and fuzzy match for paths. These matching rules are implemented in the following way:
  • Exact match: A function is triggered only when the path of the request is exactly the same as the specified path.

    Assume that you have created a route whose path is /a, the corresponding service is s1, the corresponding function is f1, and the corresponding version is 1. Only requests from exactly the /a path can trigger the f1 function of version 1. Requests from the /a/ path cannot trigger the f1 function of version 1.

  • Fuzzy match: You can append an asterisk (*) as a wildcard to a path.

    Assume that you have created a route whose path is /login/*, the corresponding service is s2, the corresponding function is f2, and the corresponding version is 1. Requests from all paths that begin with /login/, such as /login/a and /login/b/c/d, can trigger the f2 function of version 1.

Note
  • If multiple routes are configured for one custom domain name, an exact match takes precedence over a fuzzy match.
  • For a request URL that has multiple fuzzy matches, the longest prefix match (LPM) rule determines the path to use.

    Assume that the /login/a/* path and the /login/* path are configured for the custom domain name api.app.com, and the request URL is api.app.com/login/a/b. The request URL matches both configured paths. However, based on the LPM rule, the /login/a/* path is used.

Examples

Assume that the custom domain name is api.app.com. The following table describes five routing rules configured based on the steps described in this topic.
Routing rule Path Service name Function name Version
Routing rule 1 / s1 f1 1
Routing rule 2 /* s2 f2 2
Routing rule 3 /login s3 f3 3
Routing rule 4 /login/a s4 f4 4
Routing rule 5 /login/* s5 f5 5
The following table describes the final matches.
Request URL Matched service name Matched function name Matched version Matched path
api.app.com s1 f1 1 /
api.app.com/user s2 f2 2 /*
api.app.com/login s3 f3 3 /login
api.app.com/login/a s4 f4 4 /login/a
api.app.com/login/a/b s5 f5 5 /login/*
api.app.com/login/b s5 f5 5 /login/*

Verify the result

After the configuration is complete, you can use one of the following methods to access the custom domain name and verify the result:

  • Method 1: Run the curl URL command, such as curl api.app.com/login.
  • Method 2: Use a browser.

    Enter the request URL in a web browser and press the Enter key to check whether the specified function is invoked.