我正在使用一个Amazon S3桶来上传和下载数据,使用我的.NET应用程序。现在我的问题是:我想使用SSL访问我的S3存储桶。是否可以为Amazon S3桶实施SSL?
您可以通过以下方式通过SSL访问您的文件:
https://s3.amazonaws.com/bucket_name/images/logo.gif
如果您为您的存储桶使用自定义域名,您可以使用S3和CloudFront与您自己的SSL证书一起使用(或通过Amazon证书管理器生成免费证书)。http://aws.amazon.com/cloudfront/custom-ssl-domains/us-west-2
,因此主机名实际上为s3-us-west-2.amazonaws.com
,否则会出现错误。 - noetix我发现你可以通过Cloud Flare服务来轻松实现这一点。
在存储桶上设置并启用Web托管,然后通过Cloudflare将所需的CNAME指向该端点……当然要支付费用……但$5-$20相对于$600更容易接受。
完整详情请参见:https://www.engaging.io/easy-way-to-configure-ssl-for-amazon-s3-bucket-via-cloudflare/
直接在S3上不可能实现,但你可以从你的存储桶中创建一个Cloud Front分发。然后前往证书管理器并请求一个证书。亚马逊免费提供它们。一旦您成功确认了认证,将其分配给您的Cloud Front分发。还要记得设置规则以将http重定向到https。
我在Amazon S3上托管了几个静态网站,比如我的个人网站,我已经为它们分配了SSL证书,因为它们有Cloud Front分发。
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
async function handleRequest(event) {
let requestFolder = '/files'
let s3Folder = '/'
let url = new URL(event.request.url)
const cache = caches.default
let origPathname = url.pathname
const filename = url.toString().split('/').pop()
url.hostname = 'bucket-name.s3-us-west-2.amazonaws.com'
url.pathname = origPathname.replace(new RegExp('^'+escapeRegExp(requestFolder)), s3Folder)
response = await fetch(url)
response = new Response(response.body, { ...response})
return response;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\\/]/g, '\\$&');
}
以下是内容/etc/nginx/conf.d/your_file_name.conf
server {
listen 80;
server_name subkeyword.yourdomain.com;
location / {
proxy_pass http://your_bucket_name.s3-website.your_region.amazonaws.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
第三步:执行以下命令为您的子域名创建证书。sudo certbot --nginx -d subkeyword.yourdomain.com