All Products
Search
Document Center

:Configure cache expiration headers on an IIS origin server

Last Updated:Mar 30, 2026

If your CDN origin runs on Internet Information Services (IIS), you can configure HTTP cache expiration headers on the origin so that CDN nodes cache static resources for the desired duration. This topic describes how to set cache policies by directory and by file type in IIS Manager.

Background

CDN nodes determine how long to cache a resource based on the Cache-Control and Expires headers in the origin response. By default, Alibaba Cloud CDN caches common static files such as HTML, JPG, PNG, GIF, and APK files. If your origin server does not send proper cache headers, CDN nodes may not cache files as expected, which can lead to unnecessary back-to-origin requests and slower content delivery.

Scenario 1: Set cache policies by directory

Use this method when each directory contains files of the same type. For example, all images are in the img directory. The following steps use a.cc.com as an example origin site.

  1. Disable caching at the site level. This ensures that CDN does not cache files by default, so you can selectively enable caching for specific directories.

    1. Open IIS Manager, right-click the origin site (a.cc.com), and select Properties.

    2. Click the HTTP Headers tab, select Enable content expiration, select Expire immediately, and then click OK.

    3. This setting adds an Expires header that tells CDN nodes not to cache any content from this site. You will override this for specific directories in the next step.

  2. Enable caching for a specific directory.

    1. In IIS Manager, expand the site directories, right-click the target directory (for example, img), and select Properties.

    2. Click the HTTP Headers tab. Under Content expiration, select Expire after and set a cache duration, for example, 14 days. Click OK.

    3. Repeat this step for other directories that need caching, such as css or js directories.

Scenario 2: Set cache policies by file type in mixed directories

If a directory contains files with different extensions and you need different cache policies for each type, you must enable wildcard mapping in IIS and then configure per-file-type expiration through the IIS metabase.

  1. Enable wildcard application mapping. Open IIS Manager, right-click the site (a.cc.com), and select Properties. Click the Home Directory tab and then click Configuration.

  2. In the Wildcard application maps section, click Insert. Browse to and select C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll. Clear the Verify that file exists checkbox. Click OK in both dialog boxes to save the configuration.

  3. Set an expiration time for a sample file. In IIS Manager, find a file with the desired extension (for example, test.jpg in the bin directory). Right-click the file, select Properties, and click the HTTP Headers tab. Select Enable content expiration, choose Expire after, and set the cache duration. Click OK.

  4. Apply the cache policy to all files of the same type. Open the IIS metabase file at C:\WINDOWS\system32\inetsrv\MetaBase.xml in a text editor. Search for the path of the sample file (for example, /bin/test.jpg) to locate its cache policy entry. Replace the file name with a wildcard pattern (for example, change test.jpg to *.jpg) and save the file.

    Note

    Before you edit the MetaBase.xml file, stop the IIS Admin Service in the Windows Services console. Restart the service after saving your changes.

  5. Repeat steps 3 and 4 for other file types as needed.

If you need further assistance, submit a ticket.