Javascript 如何在使用时显示自定义404错误页面Lambda@Edge为从Cloudfront到私有S3存储桶的网站提供服务
我正在使用Lambda@Edge处理 “内部”从/foo/重定向到/foo/index.html和“外部” 从/foo/index.html重定向到/foo/ 我在服务自定义错误页时遇到问题 目前,我的S3 bucket中有object/404.html(也被配置为S3静态网站的错误页面,无论如何都不应该被请求,因为它应该是Cloudfront Responsibility) 在Cloudfront中,我已将/404.html设置为404状态的自定义错误页面 我应该如何设置它以返回错误页面Javascript 如何在使用时显示自定义404错误页面Lambda@Edge为从Cloudfront到私有S3存储桶的网站提供服务,javascript,amazon-s3,aws-lambda,amazon-cloudfront,aws-serverless,Javascript,Amazon S3,Aws Lambda,Amazon Cloudfront,Aws Serverless,我正在使用Lambda@Edge处理 “内部”从/foo/重定向到/foo/index.html和“外部” 从/foo/index.html重定向到/foo/ 我在服务自定义错误页时遇到问题 目前,我的S3 bucket中有object/404.html(也被配置为S3静态网站的错误页面,无论如何都不应该被请求,因为它应该是Cloudfront Responsibility) 在Cloudfront中,我已将/404.html设置为404状态的自定义错误页面 我应该如何设置它以返回错误页面 ma
marcanuy@scarone:~/Development/website$ curl -I https://example.com/wrong-page
HTTP/2 301
server: CloudFront
location: /wrong-page/
x-cache: Miss from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/wrong-page.html
HTTP/2 403
content-type: application/xml
server: AmazonS3
x-cache: Error from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/404
HTTP/2 301
server: CloudFront
location: /404/
x-cache: Miss from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/404.html
HTTP/2 200
content-type: text/html
last-modified: Fri, 03 Aug 2018 03:38:19 GMT
etag: "4ecbbfd9d1eb384afc897df3f29a8865"
accept-ranges: bytes
server: AmazonS3
x-cache: Miss from cloudfront
看起来没有返回错误页,因为CloudFront获取自定义错误页时正在执行上述函数 为了确保在从S3 bucket请求自定义错误页时不执行该函数,可以从未配置Lambda函数的不同缓存行为提供自定义错误页 例如,可以在没有任何Lambda的情况下配置路径模式为/error pages/*的缓存行为,并且可以为来自原点的404状态代码上的自定义错误页设置/error pages/404.html
marcanuy@scarone:~/Development/website$ curl -I https://example.com/wrong-page
HTTP/2 301
server: CloudFront
location: /wrong-page/
x-cache: Miss from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/wrong-page.html
HTTP/2 403
content-type: application/xml
server: AmazonS3
x-cache: Error from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/404
HTTP/2 301
server: CloudFront
location: /404/
x-cache: Miss from cloudfront
marcanuy@scarone:~/Development/website$ curl -I https://example.com/404.html
HTTP/2 200
content-type: text/html
last-modified: Fri, 03 Aug 2018 03:38:19 GMT
etag: "4ecbbfd9d1eb384afc897df3f29a8865"
accept-ranges: bytes
server: AmazonS3
x-cache: Miss from cloudfront