DCDN rules engine
The rules engine lets you use a graphical interface to configure rules. These rules use parameters from user requests to determine when a configuration applies, giving you more flexible and precise control over how DCDN configuration policies are executed.
Background
The Alibaba Cloud DCDN console provides basic features, such as configuring time-to-live (TTL) and rewriting back-to-origin parameters. While these features cover most use cases, they may not meet all requirements. For example, you might need to route requests that contain the path /example to a specific origin. To handle such scenarios, you can combine basic features with the rules engine for more flexible configurations. Additionally, Alibaba Cloud DCDN offers EdgeRoutine for advanced customization.
Configuration capability | Basic features | Basic features + rules engine | EdgeRoutine |
Implementation | General-purpose configurations | Flexible custom configurations | Highly flexible custom configurations |
Scenarios | Common use cases | Advanced custom requirements | Fully customized requirements |
Difficulty | Low | Medium | High |
Configuration flexibility | Low | Medium | High |
Limitations
You can create up to 50 rules per domain name.
Each rule can contain up to 20 sub-rules.
When you configure rules in the console or with OpenAPI, you cannot use regular expression-related operators, including regular expression match and regular expression mismatch. However, you can view existing configurations. To use these operators, submit a ticket or use ESA.
When you configure rules in the console or with OpenAPI, you can reference each rule up to five times across all features for a single domain name.
Rules can be nested up to three levels deep. Each level supports independent logical relationships.
Rule syntax
A rule consists of one or more conditional expressions that are connected by logical operators. The following sections describe the syntax.
Logical operators
Performs a logical judgment on conditions within the same level (including nested condition sets), supporting and and or.
and: The logical AND operator. A match is successful only if all conditions are true.or: A logical OR operator that results in a successful match if at least one condition is true.
Conditional expression parameters
A basic conditional expression consists of the following parameters:
Parameter | Domain configuration functioncondition and its corresponding configuration parameters | Description | Required |
Conditional match | match | Specifies the matching criteria. | Yes |
Logical operator | logic | The logical judgment parameter for the conditional matching expression, whose value can be | Yes |
Criteria | criteria | An array that contains the conditional expressions to be evaluated. | Yes |
Match type | MatchType | Specifies the type of information in a client request to evaluate. | Yes |
Match object | MatchObject | Refines the match type. For example, if the match type is client IP address, you can specify | No |
Match operator | MatchOperator | Specifies the comparison to perform. | Yes |
Match value | MatchValue | The value to compare against the information from the client request. | Yes |
Negate condition | negate | Specifies whether to negate the result of the conditional expression. Valid values: | Yes |
Case sensitivity | caseSensitive | Specifies whether the match value is case-sensitive. | No |
Rule name | name | The name of the rule. | Yes |
Status | status | The status of the rule. | Yes |
Conditional expressions
Match type | Domain configuration feature'sconditionparameters | Description | Match object | Match operator | Value | Case sensitivity | Nginx variable |
Protocol | scheme | The protocol of the client request, such as HTTP or HTTPS. | Not applicable |
|
| Not applicable | $scheme |
Request method | method | The method of the client request, such as GET or PUT. | Not applicable |
|
| Not applicable | $request_method |
URI | uri | The path in the client request URL, which does not include request parameters. For example: | Not applicable |
| The |
| $raw_uri or $uri |
File name | basename | The name of the file requested by the client. For example: | Not applicable |
| Supports wildcards |
| - |
File extension | extension | The file extension of the file requested by the client is identified from right to left up to the first period (.). For example: | Not applicable |
| Supports wildcards |
| - |
Hostname | hostname | The hostname from the client request. If a host is present in the request URL, it is used. Otherwise, the host from the | Not applicable |
| The host of the request. Multiple values are supported. |
| $host or $http_host |
Client IP address | clientip | The IP address of the client. The value can be an IPv4 address, such as |
Note For more information about POP connection IP and XFF IP, see IP address verification modes. |
| Supports IPv6 addresses, such as 240e:XXX:3004:2:3:0:0:3f7, and CIDR blocks, such as 120.209.XXX.XXX/31. Multiple values are supported. | Not applicable | $remote_addr |
Client IP version | clientipVer | The IP version of the client address: IPv4 or IPv6. |
Note For more information about POP connection IP and XFF IP, see IP address verification modes. |
|
| Not applicable | - |
Internet service provider (ISP) | geolocation | The ISP to which the client IP address belongs. |
Note For more information about POP connection IP and XFF IP, see IP address verification modes. |
| You can select an ISP from the drop-down list or enter characters to filter the options. Fuzzy search by ID or name is supported. Multiple values are supported. | Not applicable | $ip_isp_id |
IP geolocation | geolocation | The geographical location of the client IP address. |
Note For more information about POP connection IP and XFF IP, see IP address verification modes. |
| You can select a location from the drop-down list or enter characters to filter the options. Fuzzy search by ID or name is supported. Multiple values are supported. | Not applicable | $ip_country_id |
Request parameter | querystring | A parameter in the request URL. | Enter the parameter name. |
| You can use the |
| $arg_{name} |
Request header | header | A header in the client request. | You can enter a parameter name or select a parameter from the drop-down list. |
| Multiple values are supported. |
| $http_{name} |
Cookie | cookie | The cookie in the client request. | Enter the cookie name. |
| Supports wildcards |
| $cookie_{name} |
User-Agent | useragent | The User-Agent header in the client request. | Not applicable |
| You can select a value from the drop-down list or enter a UA value directly, such as |
| $http_user_agent |
Range bucket | range | Matches a specified percentage of client requests. | Not applicable |
| Enter a percentage value. | Not applicable | - |
Time | time | The time when the client request occurs. The time is in the UTC+8 time zone. For example, | Not applicable |
| Enter a time range, such as | Not applicable | - |
Nginx var | ngxvar | If the preceding variables do not meet your requirements, you can use Nginx variables. For more information, see the official Nginx documentation. | Select a variable from the drop-down list or enter a variable name. Concatenation is supported, such as |
| Multiple values are supported. | Not applicable | ${name} |
IP address verification modes
The rules engine provides two IP address verification modes. The selected mode affects how /DCDN points of presence (POPs) identify the client IP address:
POP connection IP: Matches the IP address that a client uses to connect to a DCDN node. If a proxy server is used between the client and the DCDN node, the POP connection IP is the IP address of the proxy server.
XFF IP: This mode matches the leftmost IP address in the
x-forwarded-forrequest header. The XFF IP is always the real IP address of the client, regardless of whether a proxy server is used between the client and the DCDN node.
The choice of verification mode depends on whether a client request passes through a proxy server before reaching a /DCDN POP.
Note that the execution location of the feature that references rule conditions on DCDN nodes also affects the selection of the "IP address verification mode" (for features related to origin settings that take effect on L2 nodes, the L1 nodes that a user request passes through are equivalent to intermediate proxy servers).
Example: Assume the client's real IP address is 10.10.10.10 and the proxy server's IP address is 192.168.0.1.
Without a proxy server:
The value of the
x-forwarded-forrequest header is10.10.10.10.The real client IP (the first IP from the left in the x-forwarded-for request header) = The IP address that the client uses to connect to the DCDN node =
10.10.10.10.
With a proxy server:
The value of the
x-forwarded-forrequest header in the user request is10.10.10.10,192.168.0.1.The real client IP (the leftmost IP address in the x-forwarded-for request header) is
10.10.10.10.Client-to-DCDN node connection IP = proxy server IP =
192.168.0.1.The originating client's IP address is not the same as the /DCDN POP connection IP.
Some ISPs in specific regions may assign private IP addresses to clients. As a result, /DCDN POPs may receive requests from private IP addresses.
The following are the three ranges of private IP addresses:
Class A: 10.0.0.0 to 10.255.255.255, with the subnet mask 10.0.0.0/8
Class B: 172.16.0.0 to 172.31.255.255, with the subnet mask 172.16.0.0/12
Class C: 192.168.0.0 to 192.168.255.255, with the subnet mask 192.168.0.0/16
Match operators
Operator | Domain name configuration function's condition configuration parameters | Description |
equal to | The | The condition is met only if the variable exactly matches the match value. |
not equal to | The | |
exists | The | The condition is met if the variable exists (or does not exist). |
not exists | The | |
contains any | The | The condition is met if the variable contains (or does not contain) any of the specified match values. You can specify up to 32 match values. Two types of containment matching are supported:
|
does not contain any | The | |
greater than | The | That is, |
less than | The | That is, |
greater than or equal to | The | That is, |
less than or equal to | The | That is |
regular expression match | The | The system uses the match value as a regular expression to evaluate the variable. Note You cannot configure rules with regular expression operators, including |
regular expression mismatch | The |
Wildcards
Wildcard | Description |
| Matches a single character. |
| Matches zero or more characters. |
Features supporting rule conditions
Feature category | Feature name |
origin fetch configuration | |
origin HTTP request headers (New) | |
origin HTTP response headers | |
cache configuration | |
Procedure
-
Log on to the DCDN console.
-
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage and click Configure in the Actions column.
In the left navigation pane, click Rule Engine.
Click Create Rule.
On the Create Rule page, set the Rule Name and Rule Content.
Click Submit.