In the 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 configure scripts by using the console.
Procedure
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.
NoteYou can create only one script for each domain name. To create more scripts for a domain name, Contact your account manager or contact us by other means. For more information, see Contact us.
The staging environment supports only points of presence (POPs) in the Chinese mainland.
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 are 0 to 999. A greater value indicates a lower priority. You can prioritize only scripts that are executed in the same position.
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 turn on the switch, subsequent scripts are skipped if the current script is executed.
Extensions
No
The extensions that are supported by ES. Only
_es_dbg=signature
is supported. This field enables debugging.Click Publish to Staging Environment.
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 Windows.
/etc/hosts if your client machine runs macOS.
After you complete the test, click Publish All Rules to Production Environment to publish the script to the production environment.
ImportantAfter 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 add, 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 operations.
Add, 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 use the EdgeScript CLI to configure scripts. For more information, see Use the EdgeScript CLI to manage scripts.