All Products
Search
Document Center

CDN:Use EdgeScript in the console

Last Updated:Jun 20, 2026

In the CDN console, you can create EdgeScript rules based on your EdgeScript code and publish them to the production environment to customize the management of CDN products. This topic describes how to configure and use EdgeScript in the console.

Procedure

1

  1. Log on to the CDN console.

  2. In the left navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Manage in the Actions column.

  4. Click the EdgeScript custom policy tab.

  5. Add a rule in the staging environment.

    1. On the Staging Environment tab, click Add Rule and configure an EdgeScript rule.

      Note
      • You can add only one EdgeScript rule for each domain name. To add more rules, contact your Alibaba Cloud account manager or reach out through other channels.

      • The staging environment supports only nodes in the Chinese mainland.

      The following table describes the configuration parameters.

      Parameter

      Required

      Description

      Rule Name

      Yes

      A name for the rule. It must contain only letters, digits, and underscores (_).

      Rule Code

      Yes

      The rule code.

      • Enter the rule code directly, or click Use Code Template to select a template.

      • You can write rule code based on your use case. For more information, see EdgeScript scenario examples.

      Priority

      Yes

      The rule priority. Valid values: 0 to 999. A larger value indicates a lower priority. Priorities are independent across different execution phases.

      Execution Phase

      Yes

      The execution phase of the rule. For more information, see Execution phases and priorities.

      Status

      Yes

      The status of the rule.

      Break

      No

      If enabled, prevents subsequent rules in the current phase from being executed after this rule is matched.

      Advanced

      No

      Extensions are supported. Currently, only the _es_dbg=signature field is supported. This field enables debug mode.

    2. Click Publish to Staging Environment.

  6. Test the rule in the staging environment.

    Test EdgeScript rules in the staging environment before publishing them. To do so, resolve the domain name staging.myalicdn.com to get the test IP address. Then, you must make your client resolve the accelerated domain name to this IP address.

    Add a mapping from the test IP address to the accelerated domain name in your hosts file. The paths to the hosts file are as follows:

    • Windows: C:\Windows\System32\drivers\etc\hosts.

    • macOS: /etc/hosts.

  7. After the test is complete, click Publish All Rules to Production Environment to publish the rules from the staging environment to the production environment.

    Important

    After the rules are published to the production environment, the rules in the staging environment are automatically cleared.

Revert rules in the staging environment

To clear all configurations in the staging environment and restore it to its initial state, click Revert Rules in Staging Environment. In the dialog box that appears, click OK. This deletes all configurations and reverts the staging environment to its initial state.

Modify configurations

配置修改流程

To add, modify, or delete rules, avoid editing the production environment directly. Instead, copy the rules from production to staging, make and test your changes, and then publish them to the production environment. Follow these steps:

  1. Click Revert Rules in Staging Environment to ensure that the staging environment is restored to its initial state and to prevent interference from other configurations.

  2. Click Copy Rules from Production Environment to synchronize the rules from the production environment to the staging environment. This helps prevent inconsistencies that may occur if you copy the rules manually.

  3. Add, modify, or delete rules in the staging environment.

  4. Click Publish to Staging Environment to deploy the modified rules to the staging environment. Then, test and verify the rules. For more information, see Test the rule in the staging environment.

  5. After the test is complete, click Publish All Rules to Production Environment and test the rules in the production environment to verify that the configurations work as expected.

You can also use EdgeScript with the CLI tool. For more information, see Use EdgeScript with a CLI tool.