In the Alibaba Cloud CDN console, you can create scripts based on EdgeScript (ES) coding conventions and then publish the scripts to the production environment to configure custom CDN features. This topic describes how to use ES to create a script in the CDN console.
- Log on to the Alibaba Cloud CDN 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 Manage in the Actions column.
- Click EdgeScript.
- Create a script in the staging environment.
- On the Staging Environment tab, click Add Rule to create a script. Note You can create only one script for each domain name. If you want to create multiple scripts for a domain name, Submit a ticket.
The following table describes the parameters.
Parameter Required Description Script Name Yes The name of the script that you want to create. The name can contain letters, digits, and underscores (_). Script Code Yes The content of the script.
- You can directly write a script or click Use Code Template to use a code template to write the script.
- Write a script based on your business requirements. For more information, see EdgeScript common scenarios.
Priority Yes The priority of the script. Valid values: 0 to 999. A higher value specifies a higher priority. Run Script At Yes The position at which you want to execute the script. For more information, see Positions and priorities. Enable Yes Specifies whether to enable the script. Break No Specifies whether to skip the subsequent scripts if the current script is executed. After you enable Break, the subsequent scripts are skipped if the current script is executed. Extensions No The extensions that are supported by ES. Only
_es_dbg=signatureis supported. This field enables debugging.
- Click Publish to Staging Environment.
- On the Staging Environment tab, click Add Rule to create a script.
- Test the script in the staging environment.
Before you publish a script to the production environment, you must test the script in the staging environment. To obtain the IP address that is used to test the script in the staging environment, resolve the domain name staging.myalicdn.com. Then, map the IP address to the accelerated domain name on your client machine.Add the mapping between the test IP address and the accelerated domain name to the hosts file on your client machine. The path to the hosts file is:
- C:\Windows\System32\drivers\etc\hosts if your client machine runs a Windows OS.
- /etc/hosts if your client machine runs a macOS OS.
- After you complete the test, click Publish All Rules to Production Environment to publish the script to the production environment. Notice After you publish the script to the production environment, the script is automatically deleted from the staging environment.
Roll back scripts
To clear the configurations in the staging environment and restore the staging environment to the initialized state, click Roll Back Scripts. In the message that appears, click OK.
Modify or delete scripts
If you want to modify or delete a script that is published to the production environment, we recommend that you copy the script from the production environment to the staging environment, modify and test the script in the staging environment, and then publish the modified script to the production environment. Perform the following steps:
- Click Roll Back Scripts. Make sure that the staging environment is initialized to prevent unexpected interference.
- Click Copy Rules from Production Environment to copy the script from the production environment to the staging environment. This prevents inconsistencies in the script caused by manual operation.
- Modify or delete the script in the staging environment.
- Click Publish to Staging Environment to publish the modified script to the staging environment. Then, test the script in the staging environment. For information about how to test the script in the staging environment, see Test scripts in the staging environment.
- After you complete the test, click Publish All Rules to Production Environment to publish the script to the production environment and check whether the script can meet your business requirements.
You can also run scripts in CLI. For more information, see Use the EdgeScript CLI to configure scripts.