0
votes

How do I prevent azure cdn from serving dynamic content? I only want it to serve static files: images, scripts and css but when I choose my web app as origin it serves also the root url (/), that is a dynamic page. Can I create restrictions based on file extension?

3

3 Answers

1
votes

Not at this time. Any request to the CDN edge node is going to hit the origin for the asset and cache it, whether it's dynamic or static content. The solution, then, is to ensure that your application doesn't link to any dynamic content via the CDN.

0
votes

If your static content is located in specific folders (images/, css/, etc), you can prevent the CDN from reaching content outside of those folders.

In order to prevent search engines from indexing our site via the CDN domain we have disabled site browsing on the CDN domain (except for a specific set of folders that serve resources) by adding the following urlRewrite rule to web.config:

<rule name="Deny site browsing on CDN domain" stopProcessing="true">
  <match url="^(storage/|ui/)(.*)" negate="true" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_X_HOST}" pattern="\.azureedge.net$" />
  </conditions>
  <action type="CustomResponse" statusCode="404" statusReason="Not found" statusDescription="Not found" />
</rule>
0
votes

Using web server as CDN origin is a "lazy" way to setup CDN. After you set it up, in your website instead of using:

/mypic.jpg

replace all the relative url with

xxx.azureedge.net/mypic.jpg

You don't really need to care about CDN is serving the dynamic content or not, you just need to pick the content you want. CDN just blindly serve the content from origin you specified.