Overview

This article mainly introduces how to set up CORS access for websites accelerated by Alibaba Cloud Content Delivery Network.

Background information

If a CDN node receives a non-cross-origin request for the first time after Alibaba Cloud CDN is enabled for a website, the CDN node caches the requested file without the CORS header. Before the cached file expires, errors are returned to all cross-origin requests due to the absence of the CORS header information. This situation can be avoided by setting CORS header in the way of Alibaba Cloud Content Delivery Network custom Header.

  1. Log in to the Alibaba Cloud Content Delivery Network console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, click Manage for the target domain name.
  4. In the left-side navigation pane of the specified domain name, click Cache Configuration.
  5. Select Custom HTTP Response Header and click Add.
  6. Set Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Max-Age header as needed. For details, see how Alibaba Cloud Content Delivery Network configure cross-origin resource sharing (CORS). through HTTP headers
  7. Log on to the server and use the curl command to view the set CORS header.

    Note: The CORS and other header set in the Alibaba Cloud Content Delivery Network console take effect on the entire accelerated domain name, which will overwrite the origin header set.


Application scope

  • CDN