Amazon-Web-Services

如何在 S3 中儲存 Cloudfront 自定義錯誤頁面?

  • April 18, 2022

我有一個插入 AWS 負載均衡器的 Cloudfront。

我在 AWS 文件中看到我可以自定義 Cloudfront 自定義錯誤頁面。我嘗試按照 AWS 文件中的建議將這些錯誤頁面儲存在 S3 中,但它不起作用。文件說:

We recommend that you store custom error pages in an Amazon S3 bucket even if you're using a custom origin. If you store custom error pages on an HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you want to return to viewers because the origin server is unavailable.

我的錯誤頁面位於 S3 中,路徑為“my-app-bucket/errorpage.html”。

我試圖在 Cloudfront 配置中連結此文件,但出現以下錯誤:

Cloudfront 自定義錯誤頁面配置

如果我嘗試使用值 /my-app-bucket/errorpage.html,Cloudfront 會將請求重定向到我的 ELB 源,我得到 404。

誰能解釋我如何進行此配置?

這些是來自https://web.archive.org/web/20140319123040/http://blog.celingest.com/en/2013/12/12/cloudfront-configuring-custom-error-pages/的提示

  • 您需要添加另一個指向錯誤頁面所在儲存桶的 CloudFront 源
  • 新創建的源的記憶體行為應該有一個路徑模式指向錯誤頁面所在的文件夾(在錯誤頁面儲存桶中)
  • 然後,您可以在創建自定義錯誤響應配置時在響應頁面路徑中使用該路徑

有比 f01 推薦的更簡單的方法來完成此操作。在 S3 中啟用靜態網站託管,在 S3 中指定錯誤頁面,然後使用靜態網站託管 URL 作為您的雲端儲存桶的來源。沒有特殊路徑問題,沒有自定義錯誤響應配置。它只是工作。超級容易。

這是我製作的教程影片:

AWS S3 和 Cloudfront 中的自定義錯誤頁面

引用自:https://serverfault.com/questions/642511