This topic describes how to bind a custom domain name to a web application in the Function Compute console.
- 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.
- Log on to the Function Compute console.
- In the top navigation bar, select a region.
- In the left-side navigation pane, click Custom Domain.
- Click Create Domain.
- In the Add Custom Domain panel, set the parameters and click OK.
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.
- Turn on: enables Alibaba Cloud CDN acceleration.
If you turn on CDN Acceleration, you must enter a domain name for CDN in the Accelerated Domain field. Then, log on to the Alibaba Cloud CDN console and configure a CNAME for the domain name for CDN. For more information, see Enable CDN acceleration for Function Compute origins.
- Turn off: disables CDN acceleration.
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 ConfigNotice You can configure custom domain names only for functions that have HTTP triggers. Create an HTTP trigger function before you configure routes.
- 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.
- Turn on: enables Alibaba Cloud CDN acceleration.
- 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.
- 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.
|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|
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 URLcommand, such as
- 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.