This topic describes how to bind a custom domain name to a web application in the Function Compute console.
- 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.
- 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 Configuration method Custom Domain Name Enter a custom domain name that has obtained an ICP filing 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 based on your requirements.
- Turn on: enables 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 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 the custom domain name supports 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 select Certificate Type:
- If you select Alibaba Cloud Security Certificate, you must select an Alibaba Cloud security certificate from the Certificate Name drop-down list.
- If you select Custom Certificate, 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. You can also 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, and the private key does not exceed 4 KB. 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.
- 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 function.
For more information about routes, see Routing rules.Note You can configure multiple routes.
- Turn on: enables CDN acceleration.
- 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.
|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 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 URLcommand. For example, run
- 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.