本文介绍了返回默认对象,而不会出现错误,当请求的对象没有找到,从S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能配置S3存储时未找到/提供所请求的对象返回一个默认的对象?我不希望返回任何类型的403或404错误。

Is it possible to configure S3 bucket to return a default object when the requested object is not found/available? I don't want to return any kind of 403 or 404 error.

推荐答案

在标准模式下,亚马逊S3不能被配置为返回一个默认的对象时请求的对象不可用。

In standard mode, Amazon S3 can not be configured to return a default object when the requested object is not available.

默认行为是返回一个HTTP 403时,对象不存在

The default behaviour is to return an HTTP 403 when the object does not exist

# existing object
$ curl -I http://s3-eu-west-1.amazonaws.com/public-sst/wifi.jpg
HTTP/1.1 200 OK
x-amz-id-2: K8PxI6YUES0Ua2/rPaLwKhmhZv/lVMbWnvagmfQpzs2BI6NNyHplTB4ROaYvIXCWtE/S+xXIImk=
x-amz-request-id: 9853D002E3968F0D
Date: Mon, 16 Feb 2015 11:08:56 GMT
Last-Modified: Sun, 30 Nov 2014 21:15:06 GMT
ETag: "553353dcf5d98841970e95a6d1af0741"
Accept-Ranges: bytes
Content-Type: image/jpeg
Content-Length: 113572
Server: AmazonS3

# non existing object
$ curl -I http://s3-eu-west-1.amazonaws.com/public-sst/wifi.png
HTTP/1.1 403 Forbidden
x-amz-request-id: F78E2F047DC09F00
x-amz-id-2: wydGOgs8aHMn1qc5MLbNjKGKyqshpBhA0kCgWX0zHUm0fXFRU7Z1eWdPKgtkv2ZVtPPhAqP+O+k=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Mon, 16 Feb 2015 11:08:59 GMT
Server: AmazonS3

在Amazon S3的配置在网站主机模式(按照 HTTP ://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html ),默认的行为是不同的:

When Amazon S3 is configured in web site hosting mode (as per http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html), the default behaviour is different :

  • 在HTTP 403时的对象不是公共可读返回
  • 的HTTP 404当物体或铲斗不存在或当铲斗未配置为一个网站返回。

亚马逊S3在虚拟主机模式下可以配置返回亚马逊S3生成默认的HTML HTTP 404错误的自定义错误页,而不是。

Amazon S3 in Web Hosting Mode can be configured to return a custom error page instead of the default HTML HTTP 404 error generated by Amazon S3.

由于原来的问题也提到了HTTP 403:没有办法,使用Amazon S3只配置亚马逊S3返回一个自定义错误页的HTTP 403详情见的

As the original question also mentioned HTTP 403 : there is no way, using Amazon S3 only to configure Amazon S3 to return an custom error page on HTTP 403. Details are at http://docs.aws.amazon.com/AmazonS3/latest/dev/CustomErrorDocSupport.html

要在两个HTTP 403和404返回自定义错误页,您可以在您的Amazon S3存储桶的正面使用CloudFront的。

To return a custom error page on both HTTP 403 and 404, you can use CloudFront in front of your Amazon S3 bucket.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesErrorPages

的Cloudfront可以被配置为返回自定义错误页由亚马逊S3返回的HTTP 4XX或HTTP 5xx错误。

Cloudfront can be configured to return a custom error page for any HTTP 4xx or HTTP 5xx error returned by Amazon S3.

CloudFront的分布,不会增加任何额外的费用,您只需支付带宽出来CloudFront的了。 CloudFront的传出带宽成本较低($ 0.085 / GB)比S3传出带宽(0.09 $ / GB),因此,使用CloudFront的应该是没有道理的。

CloudFront Distributions comes at no additional cost, you just pay for the bandwidth coming out of CloudFront. CloudFront outgoing bandwidth cost less ($0.085/Gb) than S3 outgoing bandwidth ($0.09 /Gb), so using CloudFront should be a no brainer.

这篇关于返回默认对象,而不会出现错误,当请求的对象没有找到,从S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:56