欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > AWS中使用CloudFront分发位于S3中的静态网站

AWS中使用CloudFront分发位于S3中的静态网站

2025/5/14 15:32:38 来源:https://blog.csdn.net/cnnews/article/details/146081828  浏览:    关键词:AWS中使用CloudFront分发位于S3中的静态网站

这是其中一种方法,可有变化

假设主页为index.html

还要准备一个证书,要覆盖子域名(AWS Certificate Manager->Certificates)

1、S3->Create bucket->Bucket name(myweb)->Create bucket

2、S3->Buckets->myweb->Upload->Add files Add folder

3、CloudFront->Distributions->Create->Origin domain(myweb.s3.amazonows.com)->Name(myweb)->Origin access(Origin access control settings (recommended))->Origin access control->Create new OAC->复制到S3->Alternate domain name (CNAME) - optional->Add item->(www.youweb.com)->Custom SSL certificate - optional(提前准备好证书)->Create distribution

4、Amazon S3->Buckets->myweb->Permissions->Bucket policy->Edit->粘贴到S3

5、Route 53->Hosted zones->配置域名记录

6、问题:www.youweb.com不能访问,只能访问www.youweb.com/index.html

6.1、办法,CloudFront Functions:

6.2、CloudFront->Functions->Create function->Name(index)->Create function

function handler(event) {var request = event.request;// 如果请求路径是根路径(/),重写为 /index.htmlif (request.uri === '/') {request.uri = '/index.html';}return request;
}

6.3、CloudFront->Functions->index->Publish->Publish function

6.4、CloudFront->Distributions->myweb->Behaviors->Edit->Function associations - optional->Viewer request->Function type->CloudFront Functions->Function ARN / Name(index)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词