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

Prerequisites

  • You have created an HTTP function.

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

  • You have applied for an Internet Content Provider (ICP) license for the custom domain name by using the Alibaba Cloud ICP Filing system or added Alibaba Cloud as a service provider to the ICP filing information of the custom domain name. For more information, see ICP filing application overview.
  • You have configured a canonical domain name (CNAME) 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 your region.
  3. In the left-side navigation pane, click Custom Domain.
  4. Click Create Domain.
  5. In the Add Custom Domain dialog box, set the parameters and click OK.
    create-domain
    Parameter Description
    Custom Domain Name Enter a custom domain name that has obtained an ICP license by using 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 as needed.
    • Turn on: enables Alibaba Cloud CDN (CDN) acceleration.

      If you turn on this switch, you must enter a domain name to accelerate in the Accelerated Domain field. Then, log on to the CDN console and configure a CNAME for the domain name to accelerate. For more information, see Enable CDN acceleration for Function Compute origins.

    • Turn off: disables CDN acceleration.
    Protocol From the Protocol drop-down list, select a protocol that the custom domain name supports. 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.

      If you need to allow users to access your custom domain name over HTTPS, you must upload a certificate and a private key in the Privacy-Enhanced Mail (PEM) format to the Function Compute console. Ensure that the certificate and private key each does not exceed 4 KB in size.

    Routing Config Configure the relationship between paths and functions. In this way, requests from different paths can trigger different functions. You must set values for the following fields:
    • Path: the path from which a request can trigger the target function.
    • Service Name: the name of the service to which the target 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 target function.

    For more information about routes, see Routing rules.

    Note You can configure multiple routes.

Routing rules

You must configure the relationship between paths and functions when you bind a custom domain name. In 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 manner:
  • 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, corresponding service is s1, corresponding function is f1, and corresponding version is 1. Only requests from exactly the /a path can trigger the f1 function under version 1. Requests from the /a/ path cannot trigger the f1 function under version 1.

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

    Assume that you have created a route whose path is /login/*, corresponding service is s2, corresponding function is f2, and 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 under 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.

Example

Assume that the custom domain name is api.app.com. The following table shows 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 shows 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 results

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

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

    Open the request URL in a web browser and then press the Enter key to check whether the target function is called.