Verifying CDN effectiveness
This topic describes how to verify whether requests pass through Alibaba Cloud CDN.
Before you begin
Initiate requests from the client network that you want to verify, and prepare the following information:
Actual resource URL: Select an image, CSS file, JavaScript file, or downloadable file. Retain the protocol, path, parameters, and required authentication information used by your business. Use the accelerated domain name to access the actual resources referenced by your business. Verify the homepage and each resource separately. The CNAME address assigned by CDN is used only for DNS configuration.
Expected CDN configuration: In the CDN console, check the accelerated domain name and its CNAME address. To connect a domain to CDN, you must configure the CNAME record at the DNS provider and configure the domain in the CDN console. Make sure that the accelerated domain name corresponding to the request domain is in the Normal state. For the onboarding process, see Alibaba Cloud CDN quick start.
Client environment: Record the test time, region, and DNS resolver. Check whether local hosts binding, proxy, or browser cache exists. These factors may change the actual request path. When verifying access from public network users, eliminate the interference of these factors and record the test environment.
Verify CDN effectiveness layer by layer
Verify in the order of DNS resolution, actual request path, cache hit, and performance comparison. Each result corresponds to the network, resource, and time of the current test. To verify other regions or resources, perform separate tests under the corresponding conditions.
Check whether DNS points to the expected CNAME
Replace the placeholder with the actual accelerated domain name. To query the CNAME record on Windows, run the following command in Command Prompt:
nslookup -type=CNAME <accelerated domain name>To query the CNAME target on Linux or macOS, run the following command in the terminal:
dig +short <accelerated domain name> CNAMEDetermine the resolution result based on the following criteria:
Full expected address returned: Compare the result with the complete CNAME assigned to the accelerated domain name in the CDN console. A trailing fully qualified domain name dot is a normal format. A match indicates that the current resolver has returned the expected CNAME. Continue to the next section to verify the actual HTTP/HTTPS request path.
Empty result or unexpected address returned: If empty output appears, use a complete DNS query to check the response status, and then determine the resolution result based on the DNS provider configuration and the actual connection IP. If your DNS provider has enabled CNAME flattening, the query may return only A or AAAA addresses. In this case, also check the provider configuration and actual connection IP.
If the resolution is abnormal, follow the instructions in CNAME query returns NXDOMAIN, no result, or an unexpected target to distinguish response status, authoritative records, and cache. Scenarios such as record conflicts, split-line resolution, console status inconsistency, and exact domain names still resolving to wildcard domain CNAMEs are handled uniformly in CNAME configuration troubleshooting guide. During troubleshooting, keep the existing DNS records and provider configuration, and process them based on the troubleshooting conclusion after the cause is located.
Check whether actual resource requests pass through CDN
Use the command line or browser developer tools to send a request to a real resource and check whether the response headers indicate that the request passed through a CDN node.
Use the command line
Send a GET request to a real resource, view the response headers, and record the connection IP. Replace the accelerated domain name and resource path with actual values. For URL authentication scenarios, use a valid complete URL. If your business request depends on request headers such as Cookie, Authorization, or Referer, carry the same necessary headers with -H when replacing the URL to reproduce the business request. The following commands discard the response body but still download the resource. Select an appropriately sized file.
Linux or macOS:
curl -sS -D - -o /dev/null -w "\nremote_ip: %{remote_ip}\n" "https://<accelerated domain name>/<resource path>"Windows Command Prompt:
curl.exe -sS -D - -o NUL -w "\nremote_ip: %{remote_ip}\n" "https://<accelerated domain name>/<resource path>"The parameters in the commands are described as follows:
-sS: Silent mode (
-s) combined with showing errors (-S). This filters out irrelevant logs such as progress bars and retains only necessary output and errors.-D -: Prints response headers directly to standard output (the screen). This is critical when troubleshooting HTTP/2 upgrades, cache policies, or security header configurations.
-o /dev/null: Discards the response body. When testing the link, you usually do not need to save the actual resource, which prevents large file content from interfering with terminal display. The Windows equivalent is
-o NUL.-w "\nremote_ip: %{remote_ip}\n": Customizes the output format and prints the actual remote IP address after the connection is established.
"https://<accelerated domain name>/<resource path>": The target accelerated domain name and resource path.
The protocol in the command must be consistent with the actual business protocol. Change the URL to HTTP when using HTTP. If a redirect occurs, first check the status code and Location to confirm the redirect target, and then verify the target URL separately. The conclusion for the final resource is based on the response of the target URL.
Use the browser developer tools
You can access an image resource under the accelerated domain name in a browser and view the response headers in the developer tools to visually determine whether the request passes through CDN.
Open a browser (for example, Google Chrome).
Open the developer tools of the browser.
Switch the tab of the developer tools to Network and select Disable cache.
Enter the URL of the image resource under the accelerated domain name in the address bar, for example,
https://<accelerated domain name>/<image path>. When the access is successful, the image is displayed in the browser.In the developer tools, click the request corresponding to the image. In the right pane, click Headers and view Response Headers.
If the response headers contain Age, X-Cache, X-Swift-SaveTime, or X-Swift-CacheTime, the accelerated domain name is correctly configured and CDN is in effect. Among them:
EagleId: A characteristic response header of Alibaba Cloud CDN. It can be used as a clue that the request has passed through CDN.
Via: Indicates the intermediate proxy nodes that the request has passed through. Identifiers such as
cachecan help identify the proxy link.
When a URL is accessed for the first time, the CDN node does not yet have a cache of the file. If the X-Cache value contains MISS, it indicates that the CDN node does not have the corresponding cached file, and the client request has fetched the file from the origin server through the CDN node.
Verify node ownership by actual connection IP
In a direct connection test without proxy interference, the remote_ip at the end of the command is the server IP address of the current connection. In the browser, you can select a specific resource request in the Network panel and view Remote Address. Use the remote_ip or Remote Address of the actual connection for this request when performing IP detection.
Use the IP detection tool to check whether the IP belongs to Alibaba Cloud CDN. If the detection result identifies it as a CDN node, you can continue the judgment based on the region, ISP, and current response. If the detection result does not identify it as a CDN node, first check the address under test, proxy, and hosts environment, and then determine the access status based on the request path evidence of the specific resource.
If CDN is connected but caching does not take effect, see Cache troubleshooting.