You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With Azure diagnostic logs, you can view core analytics and save them into one or more destinations including:
@@ -260,8 +258,8 @@ Not all metrics are available from all providers, although such differences are
260
258
| RequestCountCacheHit | Count of all requests that resulted in a Cache hit. The asset was served directly from the POP to the client. | Yes | Yes | No |
261
259
| RequestCountCacheMiss | Count of all requests that resulted in a Cache miss. A Cache miss means the asset wasn't found on the POP closest to the client, and was retrieved from the origin. | Yes | Yes | No |
262
260
| RequestCountCacheNoCache | Count of all requests to an asset that are prevented from being cached because of a user configuration on the edge. | Yes | Yes | No |
263
-
| RequestCountCacheUncacheable | Count of all requests to assets that are prevented from being cached by the asset's Cache-Control and Expires headers. This count indicates that it shouldn't be cached on a POP or by the HTTP client. | Yes | Yes | No |
264
-
| RequestCountCacheOthers | Count of all requests with cache status not covered by above. | No | Yes | No |
261
+
| RequestCountCacheUncacheable | Count of all requests to assets that are prevented from getting cached by the asset's Cache-Control and Expires headers. This count indicates that it shouldn't be cached on a POP or by the HTTP client. | Yes | Yes | No |
262
+
| RequestCountCacheOthers | Count of all requests with cache status not covered by metrics listed previously. | No | Yes | No |
265
263
| EgressTotal | Outbound data transfer in GB | Yes |Yes |Yes |
266
264
| EgressHttpStatus2xx | Outbound data transfer* for responses with 2xx HTTP status codes in GB. | Yes | Yes | No |
267
265
| EgressHttpStatus3xx | Outbound data transfer for responses with 3xx HTTP status codes in GB. | Yes | Yes | No |
@@ -271,7 +269,7 @@ Not all metrics are available from all providers, although such differences are
271
269
| EgressCacheHit | Outbound data transfer for responses that were delivered directly from the CDN cache on the CDN POPs/Edges. | Yes | Yes | No |
272
270
| EgressCacheMiss. | Outbound data transfer for responses that weren't found on the nearest POP server, and retrieved from the origin server. | Yes | Yes | No |
273
271
| EgressCacheNoCache | Outbound data transfer for assets that are prevented from being cached because of a user configuration on the edge. | Yes | Yes | No |
274
-
| EgressCacheUncacheable | Outbound data transfer for assets that are prevented from being cached by the asset's Cache-Control and, or Expires headers. Indicates that it shouldn't be cached on a POP or by the HTTP client. | Yes | Yes | No |
272
+
| EgressCacheUncacheable | Outbound data transfer for assets that are prevented from getting cached by the asset's Cache-Control and, or Expires headers. Indicates that it shouldn't be cached on a POP or by the HTTP client. | Yes | Yes | No |
275
273
| EgressCacheOthers | Outbound data transfers for other cache scenarios. | No | Yes | No |
276
274
277
275
*Outbound data transfer refers to traffic delivered from CDN POP servers to the client.
Copy file name to clipboardExpand all lines: articles/cdn/cdn-cors.md
+23-20Lines changed: 23 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,40 +2,40 @@
2
2
title: Using Azure CDN with CORS | Microsoft Docs
3
3
description: Learn how to use the Azure Content Delivery Network (CDN) to with Cross-Origin Resource Sharing (CORS).
4
4
services: cdn
5
-
documentationcenter: ''
6
-
author: zhangmanling
7
-
manager: erikre
8
-
editor: ''
9
-
5
+
author: duongau
6
+
manager: kumud
10
7
ms.assetid: 86740a96-4269-4060-aba3-a69f00e6f14e
11
8
ms.service: azure-cdn
12
9
ms.workload: tbd
13
10
ms.tgt_pltfrm: na
14
11
ms.topic: how-to
15
-
ms.date: 01/23/2017
12
+
ms.date: 02/27/2023
16
13
ms.author: mazha
17
14
18
15
---
19
16
# Using Azure CDN with CORS
17
+
20
18
## What is CORS?
21
-
CORS (Cross Origin Resource Sharing) is an HTTP feature that enables a web application running under one domain to access resources in another domain. In order to reduce the possibility of cross-site scripting attacks, all modern web browsers implement a security restriction known as [same-origin policy](https://www.w3.org/Security/wiki/Same_Origin_Policy). This prevents a web page from calling APIs in a different domain. CORS provides a secure way to allow one origin (the origin domain) to call APIs in another origin.
19
+
20
+
CORS (Cross Origin Resource Sharing) is an HTTP feature that enables a web application running under one domain to access resources in another domain. In order to reduce the possibility of cross-site scripting attacks, all modern web browsers implement a security restriction known as [same-origin policy](https://www.w3.org/Security/wiki/Same_Origin_Policy). This restriction prevents a web page from calling APIs in a different domain. CORS provides a secure way to allow one origin (the origin domain) to call APIs in another origin.
22
21
23
22
## How it works
23
+
24
24
There are two types of CORS requests, *simple requests* and *complex requests.*
25
25
26
26
### For simple requests:
27
27
28
-
1. The browser sends the CORS request with an additional**Origin** HTTP request header. The value of this header is the origin that served the parent page, which is defined as the combination of *protocol,**domain,* and *port.* When a page from https\://www.contoso.com attempts to access a user's data in the fabrikam.com origin, the following request header would be sent to fabrikam.com:
28
+
1. The browser sends the CORS request with an extra**Origin** HTTP request header. The value of the request header is the origin that served the parent page, which is defined as the combination of *protocol,**domain,* and *port.* When a page from https\://www.contoso.com attempts to access a user's data in the fabrikam.com origin, the following request header would be sent to fabrikam.com:
29
29
30
30
`Origin: https://www.contoso.com`
31
31
32
-
2. The server may respond with any of the following:
32
+
2. The server may respond with any of the following headers:
33
33
34
34
* An **Access-Control-Allow-Origin** header in its response indicating which origin site is allowed. For example:
* An HTTP error code such as 403 if the server does not allow the cross-origin request after checking the Origin header
38
+
* An HTTP error code such as 403 if the server doesn't allow the cross-origin request after checking the Origin header
39
39
40
40
* An **Access-Control-Allow-Origin** header with a wildcard that allows all origins:
41
41
@@ -51,31 +51,34 @@ A complex request is a CORS request where the browser is required to send a *pre
51
51
>
52
52
53
53
## Wildcard or single origin scenarios
54
-
CORS on Azure CDN will work automatically with no additional configuration when the **Access-Control-Allow-Origin** header is set to wildcard (*) or a single origin. The CDN will cache the first response and subsequent requests will use the same header.
55
54
56
-
If requests have already been made to the CDN prior to CORS being set on your origin, you will need to purge content on your endpoint content to reload the content with the **Access-Control-Allow-Origin** header.
55
+
CORS on Azure CDN works automatically without extra configurations when the **Access-Control-Allow-Origin** header is set to wildcard (*) or a single origin. CDN cache the first response and subsequent requests use the same header.
56
+
57
+
If requests have already been made to the CDN prior to CORS being set on your origin, you need to purge content on your endpoint content to reload the content with the **Access-Control-Allow-Origin** header.
57
58
58
59
## Multiple origin scenarios
59
-
If you need to allow a specific list of origins to be allowed for CORS, things get a little more complicated. The problem occurs when the CDN caches the **Access-Control-Allow-Origin** header for the first CORS origin. When a different CORS origin makes a subsequent request, the CDN will serve the cached **Access-Control-Allow-Origin** header, which won't match. There are several ways to correct this.
60
+
If you need to allow a specific list of origins to be allowed for CORS, things get a little more complicated. The problem occurs when the CDN caches the **Access-Control-Allow-Origin** header for the first CORS origin. When a different CORS origin makes a subsequent request, the CDN serves the cached **Access-Control-Allow-Origin** header, which doesn't match. There are several ways to correct this problem.
60
61
61
62
### Azure CDN standard profiles
62
-
On Azure CDN Standard from Microsoft, you can create a rule in the [Standard rules engine](cdn-standard-rules-engine-reference.md) to check the **Origin** header on the request. If it's a valid origin, your rule will set the **Access-Control-Allow-Origin** header with the desired value. In this case, the **Access-Control-Allow-Origin** header from the file's origin server is ignored and the CDN's rules engine completely manages the allowed CORS origins.
63
+
On Azure CDN Standard from Microsoft, you can create a rule in the [Standard rules engine](cdn-standard-rules-engine-reference.md) to check the **Origin** header on the request. If it's a valid origin, your rule set the **Access-Control-Allow-Origin** header with the desired value. In this case, the **Access-Control-Allow-Origin** header from the file's origin server is ignored and the CDN's rules engine completely manages the allowed CORS origins.
63
64
64
65

65
66
66
67
> [!TIP]
67
68
> You can add additional actions to your rule to modify additional response headers, such as **Access-Control-Allow-Methods**.
68
69
>
69
70
70
-
On **Azure CDN Standard from Akamai**, the only mechanism to allow for multiple origins without the use of the wildcard origin is to use [query string caching](cdn-query-string.md). Enable the query string setting for the CDN endpoint and then use a unique query string for requests from each allowed domain. Doing so will result in the CDN caching a separate object for each unique query string. This approach is not ideal, however, as it will result in multiple copies of the same file cached on the CDN.
71
+
On **Azure CDN Standard from Akamai**, the only mechanism to allow for multiple origins without the use of the wildcard origin is to use [query string caching](cdn-query-string.md). Enable the query string setting for the CDN endpoint and then use a unique query string for requests from each allowed domain. Doing so results in the CDN caching a separate object for each unique query string. This approach isn't ideal, however, as it results in multiple copies of the same file cached on the CDN.
71
72
72
73
### Azure CDN Premium from Verizon
73
-
Using the Verizon Premium rules engine, You'll need to [create a rule](./cdn-verizon-premium-rules-engine.md) to check the **Origin** header on the request. If it's a valid origin, your rule will set the **Access-Control-Allow-Origin** header with the origin provided in the request. If the origin specified in the **Origin** header is not allowed, your rule should omit the **Access-Control-Allow-Origin** header, which will cause the browser to reject the request.
74
74
75
-
There are two ways to do this with the Premium rules engine. In both cases, the **Access-Control-Allow-Origin** header from the file's origin server is ignored and the CDN's rules engine completely manages the allowed CORS origins.
75
+
Using the Verizon Premium rules engine, you need to [create a rule](./cdn-verizon-premium-rules-engine.md) to check the **Origin** header on the request. If it's a valid origin, your rule sets the **Access-Control-Allow-Origin** header with the origin provided in the request. If the origin specified in the **Origin** header isn't allowed, your rule should omit the **Access-Control-Allow-Origin** header, which causes the browser to reject the request.
76
+
77
+
There are two ways to resolve this problem with the Premium rules engine. In both cases, the **Access-Control-Allow-Origin** header from the file's origin server is ignored and the CDN's rules engine completely manages the allowed CORS origins.
76
78
77
79
#### One regular expression with all valid origins
78
-
In this case, you'll create a regular expression that includes all of the origins you want to allow:
80
+
81
+
In this case, you create a regular expression that includes all of the origins you want to allow:
If the regular expression matches, your rule will replace the **Access-Control-Allow-Origin** header (if any) from the origin with the origin that sent the request. You can also add additional CORS headers, such as **Access-Control-Allow-Methods**.
92
+
If the regular expression matches, your rule replaces the **Access-Control-Allow-Origin** header (if any) from the origin with the origin that sent the request. You can also add extra CORS headers, such as **Access-Control-Allow-Methods**.
90
93
91
94

92
95
@@ -96,6 +99,6 @@ Rather than regular expressions, you can instead create a separate rule for each
96
99

97
100
98
101
> [!TIP]
99
-
> In the example above, the use of the wildcard character * tells the rules engine to match both HTTP and HTTPS.
102
+
> In the example, the use of the wildcard character * tells the rules engine to match both HTTP and HTTPS.
The [Blob storage service](../storage/common/storage-introduction.md#blob-storage) in Azure Storage is one of several Azure-based origins integrated with Azure Content Delivery Network (CDN). Any publicly accessible blob content can be cached in Azure CDN until its time-to-live (TTL) elapses. The TTL is determined by the `Cache-Control` header in the HTTP response from the origin server. This article describes several ways that you can set the `Cache-Control` header on a blob in Azure Storage.
25
+
The [Blob storage service](../storage/common/storage-introduction.md#blob-storage) in Azure Storage is one of several Azure-based origins integrated with Azure Content Delivery Network (CDN). Any publicly accessible blob content can be cached in Azure CDN until its time-to-live (TTL) elapses. The TTL gets determined by the `Cache-Control` header in the HTTP response from the origin server. This article describes several ways that you can set the `Cache-Control` header on a blob in Azure Storage.
30
26
31
27
You can also control cache settings from the Azure portal by setting CDN caching rules. If you create a caching rule and set its caching behavior to **Override** or **Bypass cache**, the origin-provided caching settings discussed in this article are ignored. For information about general caching concepts, see [How caching works](cdn-how-caching-works.md).
32
28
@@ -65,7 +61,7 @@ The preferred method for setting a blob's `Cache-Control` header is to use cachi
65
61
66
62

67
63
68
-
This global caching rule sets a cache duration of one hour and affects all requests to the endpoint. It overrides any `Cache-Control` or `Expires` HTTP headers that are sent by the origin server specified by the endpoint.
64
+
This global caching rule sets a cache duration of one hour and affects all requests to the endpoint. It overrides any `Cache-Control` or `Expires` HTTP headers that get sent by the origin server specified by the endpoint.
0 commit comments