在Amazon CloudFront中,可以使用自定义错误响应功能来对所有来自源的错误响应返回404错误。下面是一个使用AWS CLI的示例代码:
{
"ErrorCode": 404,
"ResponsePagePath": "/404.html",
"ResponseCode": "404",
"ErrorCachingMinTTL": 0
}
aws cloudfront create-custom-error-response \
--distribution-id YOUR_DISTRIBUTION_ID \
--error-caching-min-ttl 0 \
--custom-error-response file://error-404.json
其中,YOUR_DISTRIBUTION_ID是你的CloudFront分发的ID。
这个命令将创建一个自定义错误响应,将来自源的所有错误响应重定向到路径为/404.html的404错误页面。ErrorCachingMinTTL设置为0表示不缓存错误页面。
请确保你已经安装了AWS CLI,并配置了适当的凭证。