S3 + CloubFront
清除 CloudFront 快取
修正了 S3 儲存桶策略,CloudFront 可能還在使用舊的快取。請執行以下步驟:
-
進入 CloudFront "Invalidations"(失效處理)。
-
建立新的 Invalidation:
- 輸入
/*,然後提交。
- 輸入
-
等待幾分鐘後再測試。
CloudFront Origin 設定錯誤 ( OAI 或 OAC )
確保你的 CloudFront 來源 (Origin) 設定正確:
-
進入 AWS CloudFront 控制台。
-
選擇你的 CloudFront Distribution。
-
前往 "Origins"(來源),確認:
-
Origin Type 是 S3。
-
Use Origin Access Control (OAC) 是 已啟用。
-
不要使用 OAI(如果有 OAI,請移除並改用 OAC)。
-
-
儲存變更。

CloudFront "Behaviors" 設定
請確保 CloudFront 的行為 (Behavior) 設定允許正確轉發請求:
-
進入 "Behaviors"(行為)頁面。
-
編輯
**/***規則:-
Viewer Protocol Policy:選擇
Redirect HTTP to HTTPS或HTTPS only。 -
Cache Policy:選擇
Managed-CachingDisabled(確保不會有快取問題)。 -
Origin Request Policy:選擇
Managed-AllViewerExceptHostHeader(允許 CloudFront 傳遞參數)。
-
測試 & 驗證
測試 CloudFront 是否可存取
如果仍然 AccessDenied,請檢查 CloudFront "Origin" 是否正確設定為 OAC。
建議使用 OAC(Origin Access Control),並確保:
-
刪除 OAI,使用 OAC 存取 S3。
-
更新 S3
**Bucket Policy**以允許 OAC 存取。 -
確認 CloudFront 的 "Origin" 設定為 OAC。
-
確認 CloudFront "Behaviors" 設定允許所有請求。
-
清除 CloudFront 快取,確保新設定生效。