跳转至

S3 + CloubFront

清除 CloudFront 快取

修正了 S3 儲存桶策略,CloudFront 可能還在使用舊的快取。請執行以下步驟:

  1. 進入 CloudFront "Invalidations"(失效處理)

  2. 建立新的 Invalidation

    • 輸入 /*,然後提交。
  3. 等待幾分鐘後再測試

CloudFront Origin 設定錯誤 ( OAI 或 OAC )

確保你的 CloudFront 來源 (Origin) 設定正確:

  1. 進入 AWS CloudFront 控制台

  2. 選擇你的 CloudFront Distribution

  3. 前往 "Origins"(來源),確認:

    • Origin TypeS3

    • Use Origin Access Control (OAC)已啟用

    • 不要使用 OAI(如果有 OAI,請移除並改用 OAC)。

  4. 儲存變更

CloudFront Origin.avif

CloudFront "Behaviors" 設定

請確保 CloudFront 的行為 (Behavior) 設定允許正確轉發請求:

  1. 進入 "Behaviors"(行為)頁面

  2. 編輯 **/*** 規則

    • Viewer Protocol Policy:選擇 Redirect HTTP to HTTPSHTTPS only

    • Cache Policy:選擇 Managed-CachingDisabled(確保不會有快取問題)。

    • Origin Request Policy:選擇 Managed-AllViewerExceptHostHeader(允許 CloudFront 傳遞參數)。

測試 & 驗證

測試 CloudFront 是否可存取

curl -I https://your-cloudfront-domain.cloudfront.net/front/index.html

如果仍然 AccessDenied,請檢查 CloudFront "Origin" 是否正確設定為 OAC

建議使用 OAC(Origin Access Control),並確保:

  1. 刪除 OAI,使用 OAC 存取 S3。

  2. 更新 S3 **Bucket Policy** 以允許 OAC 存取。

  3. 確認 CloudFront 的 "Origin" 設定為 OAC

  4. 確認 CloudFront "Behaviors" 設定允許所有請求

  5. 清除 CloudFront 快取,確保新設定生效。