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. For more information, see Procedure.
Requests sent from a custom domain name can trigger only HTTP functions.
- An Internet Content Provider (ICP) license for the custom domain name is applied for by using 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 inQuick Start.
Procedure
Routing rules
- Exact match: A function is triggered only when the path of the request is exactly
the same as the specified path.
For example, 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 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 character to a path.
For example, 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 of version 1.
- 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.
For example, 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
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 |
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, runcurl api.app.com/login
. - Method 2: Use a browser.
Enter the request URL in a web browser and then press the Enter key to check whether the specified function is called.