API Gateway allows you to bind wildcard domain names to API groups. You can resolve a wildcard domain name to API Gateway and then bind the wildcard domain name to your API group in the API Gateway console. After the binding is complete, you can use the wildcard domain name to call API operations under the API group hosted on API Gateway.

Assume that you are the owner of the domain name abc.com. If you want to resolve all subdomains such as 1.abc.com and 2.abc.com of abc.com to API Gateway to provide external services, follow these steps:

  1. On your DNS management platform, use a CNAME record to resolve *.abc.com to an Internet second-level domain name of the target API group hosted on API Gateway.
  2. On the API Groups page of the API Gateway console, bind *.abc.com to the target API group.

After the binding is complete, the client can access API operations under the API group by using any of subdomains of abc.com. For example, if an API operation under the API group can be called anonymously by using the GET method, the API operation can also be called by using the subdomains of *.abc.com.

The following example describes the procedure for binding the test wildcard domain name *.test.yourdomain.com to API Gateway. After the binding is complete, you can use its subdomains such as 1.test.yourdomain.com and 2.test.yourdomain.com to access API Gateway.

1. Change the DNS settings of the wildcard domain name

Step 1 On the Group Details page of the API Gateway console, find the Internet second-level domain name provided for the target API group.

Step 2 Log on to your DNS management platform. If you use Alibaba Cloud DNS, visit https://dns.console.aliyun.com. On the Manage DNS page of the Alibaba Cloud DNS console, click the target domain name to go to the DNS Settings page.

Step 3 Click Add Record. In the Add Record dialog box, set Type to CNAME, Host to *.test, and Value to the Internet second-level domain name that you obtained in step 1, and then click OK.

2. Bind the wildcard domain name to the target API group in the API Gateway console

Step 1 Log on to the API Gateway console. In the left-side navigation pane, click API Groups. On the page that appears, click the group to which you want to bind the wildcard domain name. The Group Details page appears. Step 2 In the lower-right part of the Group Details page, click Bind Domain. Step 3 In the Bind Domain Name dialog box, enter the wildcard domain name *.test.yourdomain.com for which you complete DNS settings and click OK.

After the binding is complete, you can use this wildcard domain name to call any API operation under the API group. The following example shows how to call an API operation by using cURL.

curl http://1.test.yourdomain.com/apipath -i
HTTP/1.1 200 OK
Date: Mon, 23 Mar 2020 08:40:01 GMT
Connection: keep-alive
Keep-Alive: timeout=25
Server: Jetty(7.2.2.v20101205)
X-Ca-Request-Id: E2B8CBAB-D6EF-4576-838F-44DDC1A6B20D

curl http://2.test.fredhuang.com/httpCommon -i
HTTP/1.1 200 OK
Date: Mon, 23 Mar 2020 08:40:56 GMT
Connection: keep-alive
Keep-Alive: timeout=25
Server: Jetty(7.2.2.v20101205)
X-Ca-Request-Id: C0688191-BFFC-4571-BE74-5F82B0C0A731

3. Limits

  1. Before you bind a wildcard domain name to an API group hosted on API Gateway, you must resolve the wildcard domain name to the second-level domain name of the group. Otherwise, the binding fails.
  2. Only instances (VPC) support wildcard domain names.