This article mainly introduces how to set up CORS access for websites accelerated by Alibaba Cloud Content Delivery Network.
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.
- Log in to the Alibaba Cloud Content Delivery Network console.
- In the left-side navigation pane, click Domain Names.
- On the Domain Names page, click Manage for the target domain name.
- In the left-side navigation pane of the specified domain name, click Cache Configuration.
- Select Custom HTTP Response Header and click Add.
- 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
- 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.