Function Compute provides default access URLs for created HTTP triggers. When you access the URLs by using a browser, forced downloads are triggered. If you want to access a function by using a browser without triggering forced downloads or by using a fixed domain name, you must configure a custom domain name.
Common scenarios
You can create functions in Function Compute to process HTTP requests. The following items describe common scenarios in which you must bind custom domain names to web applications:
You create a web application and migrate the application to Function Compute and want to access the web application by using a fixed domain name.
You build a web application in the Function Compute console and want to use different paths of a domain name to trigger different functions.
Prerequisites
A function and an HTTP trigger are created. For more information, see Create a function and Step 1: Create a trigger.
Limits
Domain names that contain Chinese characters are not supported.
The configured custom domain name is case-sensitive. Use the actual domain name for which an Internet Content Provider (ICP) filing is obtained.
You can configure wildcard domain names and standard domain names.
A domain name can be up to 256 characters in length. The subdomain name at each level must contain at least one character and can be up to 63 characters in length. A subdomain name can contain letters (case-sensitive), digits (0-9), and hyphens (-). However, a domain name cannot start with a hyphen (-). The last part of a domain name, or the top-level domain name, must be a string of alphabetic characters that is at least two characters in length.
Procedure
Process of configuring a custom domain name
Step 1: Obtain ICP filing
Obtain an ICP filing for the domain name based on the service provider and account to which the domain name belongs. Refer to the corresponding operation guide to complete the process.
You do not need to apply for an ICP filing for custom domain names that are bound to functions in China (Hong Kong) or regions outside the Chinese mainland.
You can query the service provider of a domain name on WHOIS.
You can check whether a domain name belongs to the current Alibaba Cloud account in the Alibaba Cloud DNS console.
Domain names registered by the current Alibaba Cloud account
Apply for an Internet Content Provider (ICP) filing for a custom domain name in the Alibaba Cloud ICP Filing system. For more information, see Overview.
Domain names registered by other Alibaba Cloud accounts
We recommend that you use the Alibaba Cloud account that is used to register the domain name to obtain the ICP filing for the domain name. Log on to the Alibaba Cloud ICP Filing system to apply for an ICP filing for the custom domain name. For more information, see Overview.
Domain names registered by non-Alibaba Cloud accounts
If the entity and the domain name have been filed through another service provider, you need to transfer the ICP filings to Alibaba Cloud web hosting by changing the service provider to Alibaba Cloud or add Alibaba Cloud as a new service provider for the website. Log on to the Alibaba Cloud ICP Filing system to apply for an ICP filing for the custom domain name.
Step 2: Configure domain name resolution
For more information, see Quick Start.
You need to resolve the domain name to an endpoint of Function Compute in the corresponding region. That is, you need to configure the CNAME of the custom domain name to an endpoint of Function Compute. On the DNS page, set Record Type to CNAME and Record Value to an endpoint of Function Compute.
The following table describes formats of Function Compute endpoints.
Endpoint type | Format | Example | |
Public endpoints |
| Custom domain: example.com Alibaba Cloud account: 164901546557**** Region: China (Shanghai) | Public endpoint: |
Internal endpoints |
| Internal endpoint: |
If you want to access the domain name over the Internet, you must set Record Value to a public endpoint of Function Compute.
Step 3: Add a custom domain name
Log on to the Function Compute console. In the left-side navigation pane, choose .
In the top navigation bar, select a region. On the Custom Domains page, click Add Custom Domain Name.
On the Add Custom Domain Name page, configure the parameters and click Create. The following table describes the parameters.
Parameter
Description
Basic Settings
Domain Name
Enter a custom domain name for which an ICP filing has been obtained in the Alibaba Cloud ICP Filing system or the custom domain name whose ICP filing information includes Alibaba Cloud as a service provider. You can enter a specific domain name such as
www.aliyun.com
or a wildcard domain name such as*.aliyun.com
.Route Settings
Route
Configure the mapping between paths and functions. This way, requests from different paths can trigger different functions. You must configure the following fields:
Path: the request path from which the specified function can be triggered.
Function Name: the name of the function that is triggered by a request from a specified path.
Version or Alias: the version or alias of the function that is triggered by requests from the specified path.
Rewrite Policy: the rule based on which the Uniform Resource Identifier (URI) of a request in a specified path is rewritten. For more information, see Procedure.
You can configure multiple routes. For more information, see Route matching rule.
HTTPS Settings
HTTPS
Select Enable or Disable to allow or disallow the custom domain name to be accessed over HTTPS. Options:
Enable: allows the custom domain name to be accessed over HTTPS. If you select Enable, you can access the custom domain name over HTTP or HTTPS.
NoteYou can also select the Redirects HTTP Requests to HTTPS check box to allow only HTTPS requests to access the custom domain name. Function Compute redirects requests that are accessed over HTTP to HTTPS.
Disable: disallows the custom domain name to be accessed over HTTPS. If you select Disable, you can access the custom domain name only over HTTP.
Certificate type
Select the type of the certificate that you want to upload. This parameter is required if you select Enable for the HTTPS parameter. A tag consists of the following parameters:
Alibaba Cloud SSL Certificate: Specify an Alibaba Cloud SSL certificate in Certificate Name. If no values are available in the Certificate Name drop-down list, you do not have an Alibaba Cloud SSL certificate. In this case, log on to the Certificate Management Service console to purchase an SSL certificate.
Manual Upload: Configure a certificate by specifying the Certificate Name, PEM Certificate Content, and PEM Certificate Key parameters.
NoteThe certificate that you want to upload cannot exceed 20 KB in size. The certificate key cannot exceed 4 KB in size.
TLS Version
Select the transport layer security (TLS) protocol version that the function uses from the drop-down list. If you leave this parameter empty, TLS 1.0 or a later version is used, including TLS 1.0, TLS 1.1, and TLS 1.2. Valid values:
TLS 1.0 and Later (Best Compatibility and Low Security): TLS 1.0, TLS 1.1, and TLS 1.2 are supported.
TLS 1.1 and Later (High Compatibility and High Security): TLS 1.1 and TLS 1.2 are supported.
TLS 1.2 and Later (High Compatibility and Best Security): TLS 1.2 is supported.
NoteAfter you select a TLS version, you can also select the Enable Support for TLS1.3 check box. This way, TLS 1.3 is supported.
Cipher Suite
Specify TLS cipher algorithm suites. If you leave this parameter empty, all cipher suites are selected. Valid values:
All Cipher Suites (High Compatibility and Low Security): All cipher suites. For the list of cipher suites supported by Function Compute, see Strong and weak cipher suites.
Custom Cipher Suite (Select Based on Protocol Version. Proceed with Caution): Select cipher suites based on your business requirements. All cipher suites are displayed in the drop-down list. You can click the icon to the right of a weak cipher suite to delete the cipher suite and retain the cipher suites that are supported by the versions of the TLS protocol that you selected.
ImportantSelect custom cipher suites with caution. Ensure that the cipher suites that are used by clients match the cipher suites that are used by the server.
For more information about mappings between TLS versions and cipher suites, see Mappings between TLS versions and cipher suites.
Function Compute names cipher suites based on the RFC naming convention. Names of cipher suites vary based on the naming convention. For more information about mappings between RFC and OpenSSL cipher suites, see Mappings between names of RFC cipher suites and OpenSSL cipher suites.
Authentication Settings
Authentication Method
No Authentication: No authentication is required for HTTP requests, and anonymous access is supported. Anyone can initiate HTTP requests to invoke your function.
Signature verification: Signature authentication is required on HTTP requests. For more information, see Configure signature authentication for custom domain names.
JWT authentication: JWT authentication is required on HTTP requests. For more information, see Configure JWT authentication for custom domain names.
WAF Settings
Web Application Firewall (WAF)
Specifies whether to enable WAF for the custom domain name. WAF identifies malicious traffic in functions and applications, scrubs and filters out malicious traffic, and returns normal traffic to backend functions to protect your functions against malicious intrusions. For more information, see Enable WAF protection.
CDN Settings
CDN Acceleration
Specify whether to enable CDN acceleration for the custom domain name. If you enable CDN acceleration for the custom domain name, end users can use the CDN-accelerated domain name to read data with high efficiency. Valid values:
Enable: enables CDN acceleration. If you set the CDN Acceleration parameter to Enable, you must enter an accelerated domain name in the CDN-Accelerated Domain Name field. Then, log on to the CDN console and configure a CNAME record for the accelerated domain name. For more information, see (Optional) Step 4: Enable CDN acceleration.
Disable: disables CDN acceleration.
After you configure the custom domain name, you can modify or delete it based on your business requirements.
ImportantIf you delete a custom domain name, all requests that use the domain name to access Function Compute fail. Exercise caution when you perform this operation.
(Optional) Step 4: Enable CDN acceleration
After you bind a custom domain name to a web application, you can use the custom domain name as the origin domain name and add an accelerated domain name to it. Then, you can configure a CNAME for the accelerated domain name. This way, CDN acceleration is enabled for the custom domain name. The application that is deployed in Function Compute serves as an origin server, and the source content is published to edge nodes. This way, end users can read the required content with high efficiency. This efficiently reduces the latency and improves service quality.
After you add the accelerated domain name, you can check whether CDN acceleration is enabled for your custom domain name in the Function Compute console and whether the specified accelerated domain name that is added in the CDN console is bound to your custom domain name.
If you enable the CDN acceleration feature, you are charged for data transferred over the Internet. For more information, see Billing overview.
The custom domain name and the accelerated domain name cannot be the same. For example, if you set the custom domain name to www.test.com, you must set the accelerated domain name to another domain name, such as cdn.test.com.
Log on to the CDN console and enable CDN acceleration.
For more information, see Add a domain name.
When you configure the Origin Info parameter, select Function Compute Domain. Then, select the region where the Function Compute service that you want to manage resides and the custom domain name that you created.
Log on to the Function Compute console. In the left-side navigation pane, choose .
In the top navigation bar, select a desired region. In the domain name list, find the domain name that you want to manage and click Modify in the Actions column.
On the Modify Custom Domain Name page, view the CDN-accelerated domain name configurations that are synchronized from the CDN console.
After the CDN domain name is added to the custom domain name, CDN assigns a CNAME to the custom domain name. Obtain the CNAME record on the Custom Domains page and map the DNS parsing of the accelerated domain to the CNAME record.
For more information, see Add a CNAME record for a domain name.
NoteThe CNAME is in the following format:
Accelerated domain name.w.alikunlun.com
, for example,example.aliyundoc.com.w.alikunlun.com
.
Step 5: Verify the custom domain name
After the preceding operations are complete, you can use one of the following methods to check whether the custom domain name or the CDN-accelerated domain name can be accessed.
Method 1: Run
curl URL
, such ascurl example.com/login
.Method 2: Use a browser.
Enter the request URL in the address bar of a browser and press the Enter key to check whether the specified function is invoked.
Cipher suites
Strong and weak cipher suites
Mapping between TLS versions and cipher suites
Mappings between names of RFC cipher suites and OpenSSL cipher suites
Matching rule
Route matching rule
You must configure the mapping 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 matching and fuzzy matching for paths. The following items describe the matching rules:
Exact match: A function is triggered only if the path of the request is exactly the same as the specified path.
For example, you created a route whose path is /a, the corresponding function is Function 1, and the corresponding version is Version 1. Only requests from the /a path can trigger Function 1 of Version 1.
Fuzzy match: You can append an asterisk (*) as a wildcard to a path.
For example, you created a route whose path is, /login/*, the corresponding function is Function 2, and the corresponding version is Version 1. Requests from 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, exact matching takes precedence over fuzzy matching.
The longest prefix match (LPM) rule applies when fuzzy matches are performed.
For example, if the /login/a/* path and the /login/* path are configured and the custom domain name is
example.com
, the request URL is example.com/login/a/b. The request URL matches the configured paths. However, the /login/a/* path is used based on the longest prefix match (LPM) rule.
Example
For example, the custom domain name is example.com
and five routing rules are configured based on the steps described in this topic. The following table lists the routing rules.
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 | Name of matched service | Name of matched function | Matched version | Matched path |
example.com | s1 | f1 | 1 | / |
example.com/user | s2 | f2 | 2 | /* |
example.com/login | s3 | f3 | 3 | /login |
example.com/login/a | s4 | f4 | 4 | /login/a |
example.com/login/a/b | s5 | f5 | 5 | /login/* |
example.com/login/b | s5 | f5 | 5 | /login/* |
Domain name matching rule
Function Compute matches a domain name based on the domain name information in your request and forwards the request to the function that corresponds to the matched domain name. Function Compute supports exact matching and fuzzy matching for domain names. The following items describe the matching rules:
Exact matching: The function that corresponds to the domain name can be triggered only if the domain name of the request exactly matches the custom domain name that you created.
Fuzzy matching: Wildcard domain names are supported. The function can be triggered if the domain name of the request partially matches the custom domain name that you created. A maximum of one wildcard character (*) can be contained in a domain name, and the wildcard character must be placed at the beginning of the domain name.
If a request matches a single domain name and a wildcard domain name at the same time, the request is forwarded to the function that corresponds to the single domain name.
In fuzzy matching, a wildcard domain name can match only a domain name at the same level. For example,
*.aliyun.com
can matchfc.aliyun.com
, but notcn-hangzhou.fc.aliyun.com
.*.aliyun.com
andfc.aliyun.com
are third-level domains andcn-hangzhou.fc.aliyun.com
is a fourth-level domain.
Example
The following table shows the results of request domain names that match the following existing domain names: fc.aliyun.com
, *.aliyun.com
, and *.fc.aliyun.com
.
Request domain name | Matched domain name |
fc.aliyun.com | fc.aliyun.com |
fnf.aliyun.com | *.aliyun.com |
cn-hangzhou.fc.aliyun.com | *.fc.aliyun.com |
accountID.cn-hangzhou.fc.aliyun.com | None |
FAQ
Can a public endpoint of an HTTP trigger be used in a production environment?
What do I do if a 502 Bad Gateway error is reported when I access a custom domain name?
What do I do is errors are reported when I use a Chinese domain name to configure a custom domain name?
How do I resolve the issue of forced downloads when I access a domain name through a browser?
What do I do if a 301 redirect occurs when I access an accelerated domain name?
What do I do if I cannot select an existing function when I configure routes?
What do I do if a function cannot be triggered by using a route?
Diagnostics
If an error occurs when you bind a custom domain name, the server returns an error message. The following table describes common error codes to help you quickly identify and resolve issues.
Error code | HTTP status code | Error message | Possible cause |
InvalidICPLicense | 400 | domain name '%s' has not got ICP license, or the ICP license does not belong to Aliyun | This error is reported because the domain name does not have an ICP filing or the information in the ICP filing does not include Alibaba Cloud as a service provider. For more information, see Step 1: Obtain ICP filing. |
DomainNameNotResolved | 400 | domain name '%s' has not been resolved to your FC endpoint, the expected endpoint is '%s' | The error message returned because no CNAME is configured for the domain name to point to the specified endpoint. You can check the CNAME settings by running the dig command or logging on to the Domain Name System (DNS) server. |
DomainRouteNotFound | 404 | no route found in domain '%s' for path '%s' | The error message returned because no function is configured for the specified path. |
TriggerNotFound | 404 | trigger 'http' does not exist in service '%s' and function '%s' | The error message returned because no HTTP trigger is configured for the function that is bound to the custom domain name. |
DomainNameNotFound | 404 | domain name '%s' does not exist | The error message returned because the domain name that you want to query does not exist. |
DomainNameAlreadyExists | 409 | domain name '%s' already exists | The error message returned because the domain name that you want to bind already exists. |
If the issue persists, join the DingTalk group 64970014484 for technical support.