AmazonS3:自定义错误页面 [英] AmazonS3: custom error pages

查看:201
本文介绍了AmazonS3:自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划共享私有对象的URL(限时).有没有一种方法可以为404/403 http响应设置自定义错误页面?

I am planning to share URLs (time limited) for private objects. Is there a way to set custom error pages for 404/403 http responses ?

推荐答案

是的,有可能,请参见开发人员指南中,有一段有关自定义错误文档支持"中的以下句子.

Yes, it's possible, see this announcement. In the Developer guide there is a paragraph about "Custom Error Document Support" where I read the following sentence.

您可以选择提供自定义 用户友好的错误文档 错误消息以及其他 帮助.您提供此自定义错误 文档作为添加网站的一部分 配置到您的存储桶.亚马逊 S3返回您的自定义错误文档 仅针对HTTP 4XX类错误 代码.

You can optionally provide a custom error document with a user-friendly error message and with additional help. You provide this custom error document as part of adding website configuration to your bucket. Amazon S3 returns your custom error document for only the HTTP 4XX class of error codes.

如何设置4xx自定义错误页面:

How to set 4xx custom error page:

  • 使用 CloudBerry ,您可以右键单击存储桶,选择属性",单击网站"标签并设置索引文档和4xx错误文档.

  • With CloudBerry, you can right click on a bucket, select Properties, click the tab Website and set the index document and the 4xx error document.

使用 AWS Java SDK ,这是示例代码(未经测试)

Use AWS Java SDK, here is an example code (not tested)

AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(
    "accessKey", "secretKey");
BucketWebsiteConfiguration conf = new BucketWebsiteConfiguration(
    "index.html", "404.html");
client.setBucketWebsiteConfiguration("bucketname.example.com", conf);

更新我也发现了此博客文章:

UPDATE I also found this blog post: Host Your Static Website on Amazon S3.

这篇关于AmazonS3:自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆