

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用受管回應標頭政策
<a name="using-managed-response-headers-policies"></a>

藉助 CloudFront 回應標頭政策，您可以指定 Amazon CloudFront 移除或新增至傳送給檢視者之回應的 HTTP 標頭。如需回應標頭政策及其使用原因的詳細資訊，請參閱[在 CloudFront 回應中使用政策新增或移除 HTTP 標頭](modifying-response-headers.md)。

CloudFront 提供受管回應標頭政策，您可以將這些政策連接至 CloudFront 發佈中的快取行為。使用受管回應標頭政策，您不需要撰寫或維護自己的政策。受管政策包含適用於常見使用案例的 HTTP 回應標頭集。

若要使用受管回應標頭政策，請將其連接至分佈中的快取行為。這項程序與建立自訂回應標頭政策的程序相同，只不過您並不會建立新政策，而是連接其中一項受管政策。您可以依名稱 （使用主控台） 或 ID CloudFormation（使用 AWS CLI、 或 AWS SDKs) 連接政策。名稱和 ID 會列在下一節中。

如需詳細資訊，請參閱[建立回應標頭政策](creating-response-headers-policies.md)。

下列主題說明您可以使用的受管回應標頭政策。

**Topics**
+ [CORS-and-SecurityHeadersPolicy](#managed-response-headers-policies-cors-security)
+ [CORS-With-Preflight](#managed-response-headers-policies-cors-preflight)
+ [CORS-with-preflight-and-SecurityHeadersPolicy](#managed-response-headers-policies-cors-preflight-security)
+ [SecurityHeadersPolicy](#managed-response-headers-policies-security)
+ [SimpleCORS](#managed-response-headers-policies-cors)

## CORS-and-SecurityHeadersPolicy
<a name="managed-response-headers-policies-cors-security"></a>

[在 CloudFront 主控台中檢視此政策](https://console.aws.amazon.com/cloudfront/v4/home#/policies/responseHeaders/e61eb60c-9c35-4d20-a928-2b84e02af89c)

使用此受管政策允許來自任何原始伺服器的簡單 CORS 請求。此政策也會將一組安全性標頭新增至 CloudFront 傳送給檢視者的所有回應。這項政策將 [SimpleCORS](#managed-response-headers-policies-cors) 和 [SecurityHeadersPolicy](#managed-response-headers-policies-security) 政策結合為一個政策。

使用 CloudFormation AWS CLI、 或 CloudFront API 時，此政策的 ID 為：

`e61eb60c-9c35-4d20-a928-2b84e02af89c`


**政策設定**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html)

## CORS-With-Preflight
<a name="managed-response-headers-policies-cors-preflight"></a>

[在 CloudFront 主控台中檢視此政策](https://console.aws.amazon.com/cloudfront/v4/home#/policies/responseHeaders/5cc3b908-e619-4b99-88e5-2cf7f45965bd)

使用此受管政策可允許來自任何原始伺服器的 CORS 請求，包括預檢請求。對於預檢請求（使用 HTTP `OPTIONS` 方法），CloudFront 將以下三個標頭新增至回應中。對於簡單 CORS 請求，CloudFront 只新增 `Access-Control-Allow-Origin` 標頭。

如果 CloudFront 從原始伺服器收到的回應包含任何這些標頭，CloudFront 會在傳送給檢視者的回應中使用接收到的標頭 (及其值)，而不是此政策中的標頭。

使用 CloudFormation AWS CLI、 或 CloudFront API 時，此政策的 ID 為：

`5cc3b908-e619-4b99-88e5-2cf7f45965bd`


**政策設定**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html)

## CORS-with-preflight-and-SecurityHeadersPolicy
<a name="managed-response-headers-policies-cors-preflight-security"></a>

[在 CloudFront 主控台中檢視此政策](https://console.aws.amazon.com/cloudfront/v4/home#/policies/responseHeaders/eaab4381-ed33-4a86-88ca-d9558dc6cd63)

使用此受管政策可允許來自任何原始伺服器的 CORS 請求，包含預檢請求。此政策也會將一組安全性標頭新增至 CloudFront 傳送給檢視者的所有回應。這項政策將 [CORS-With-Preflight](#managed-response-headers-policies-cors-preflight) 和 [SecurityHeadersPolicy](#managed-response-headers-policies-security) 政策結合為一個政策。

使用 CloudFormation AWS CLI、 或 CloudFront API 時，此政策的 ID 為：

`eaab4381-ed33-4a86-88ca-d9558dc6cd63`


**政策設定**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html)

## SecurityHeadersPolicy
<a name="managed-response-headers-policies-security"></a>

[在 CloudFront 主控台中檢視此政策](https://console.aws.amazon.com/cloudfront/v4/home#/policies/responseHeaders/67f7725c-6f97-4210-82d7-5512b31e9d03)

使用此受管政策，將一組安全性標頭新增至 CloudFront 傳送給檢視者的所有回應。如需這些安全性標頭的詳細資訊，請參閱 [Mozilla 的 Web 安全指南](https://infosec.mozilla.org/guidelines/web_security)。

使用這項回應標頭政策後，CloudFront 會為所有回應新增 `X-Content-Type-Options: nosniff`，無論 CloudFront 從原始伺服器收到的回應是否包含這個標頭都一樣。但如果 CloudFront 從原始伺服器收到的回應所包含的是此政策中的其他任何標頭，則 CloudFront 會在傳送給檢視者的回應中使用接收到的標頭 (及其值)，而不是此政策中的標頭。

使用 CloudFormation AWS CLI、 或 CloudFront API 時，此政策的 ID 為：

`67f7725c-6f97-4210-82d7-5512b31e9d03`


**政策設定**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html)

## SimpleCORS
<a name="managed-response-headers-policies-cors"></a>

[在 CloudFront 主控台中檢視此政策](https://console.aws.amazon.com/cloudfront/v4/home#/policies/responseHeaders/60669652-455b-4ae9-85a4-c4c02393f86c)

使用此受管政策允許來自任何原始伺服器的[簡單 CORS 請求](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests)。使用此政策，CloudFront 將標頭 `Access-Control-Allow-Origin: *` 新增至簡單 CORS 請求的所有回應。

如果 CloudFront 從原始伺服器收到的回應包含 `Access-Control-Allow-Origin` 標頭，CloudFront 會在傳送給檢視者的回應中使用該標頭 (及其值)，而不是此政策中的標頭。

使用 CloudFormation AWS CLI、 或 CloudFront API 時，此政策的 ID 為：

`60669652-455b-4ae9-85a4-c4c02393f86c`


**政策設定**  

|  | 標頭名稱 | 標頭值 | 是否覆寫原始伺服器？ | 
| --- | --- | --- | --- | 
| CORS 標頭： | Access-Control-Allow-Origin | \$1 | 否 | 