简体   繁体   中英

CNAME to s3 bucket amazon

I would like to use a subdomain instead of the direct url to my s3 bucket at amazon.com. So instead of downloading images via an url like http://bucket-images.s3-eu-west-1.amazonaws.com/path/to/image.png I would like to use http://assets.domain.com/path/to/image.png . I tried setting a CNAME like this:

CNAME   assets   domain.com    bucket-images.s3-eu-west-1.amazonaws.com

But after setting this CNAME I receive such error from amazon, when I visit the domain:

<Error>
    <Code>NoSuchBucket</Code>
    <Message>The specified bucket does not exist</Message>
    <BucketName>assets.domain.com</BucketName>
    <RequestId>45646DFSDFSFASDF</RequestId>
    <HostId>
        dfasdcvcvd546456454ds5fasdf4ad5f64asdfasdfccdfgvggtg
    </HostId>
</Error>

Over here they're telling to change the bucketname: https://forums.aws.amazon.com/message.jspa?messageID=237562 But that doesn't make sense. I worked on a project earlier, who used a bucketname totally different from the subdomain. So there has to be a way... Anyone who can help me out?

For S3 you need the CNAME and bucket name to match:

The bucket name must be the same as the CNAME. So http://images.johnsmith.net/filename would be the same as http://images.johnsmith.net.s3.amazonaws.com/filename if a CNAME were created to map images.johnsmith.net to images.johnsmith.net.s3.amazonaws.com

So in your specific example you need to name the bucket assets.domain.com .

http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingCustomURLs

If you need more flexibility, you can create a CloudFront distribution for your S3 bucket and assign a CNAME to your CloudFront distribution.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html

Addtional to @Samuel Neff's information:

Just remember to name your AWS S3 bucket same as your Cloudflare CNAME record. Otherwise it will not work.

Here I tried and worked for me:

Converted https://s3-eu-west-2.amazonaws.com/cdn.domain.com to http://cdn.domain.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM