I have a site hosted on a digital ocean droplet which serves both static and dynamic content. The static content (e.g. /images, /js, /css, /fonts) is served from an s3 bucket with folders /images, /js, /css, /fonts
via cloudfront which has a path pattern behaviour of Default (*)
. To use a custom url for this distribution i added an alternate name of assets-dev.example.com
and added a cname record in my DNS control panel which points assets-dev.example.com to the cloudfront distribution. This part all works fine.
Now I want to serve the rest of my site e.g. dev.example.com which also serves dynamic content via cloudfront.
I tried to set up a custom origin using domain dev.example.com
and added another alternate name for the distribution of dev.example.com
However in my DNS control panel I have an A record pointing dev.example.com
to my digital ocean droplet and get an error if I try to add a cname record with dev.example.com
pointing to the cloudfront url.
So my questions are:
- What's the correct way to configure the DNS settings so that
dev.example.com is returning content from cloudfront which then gets
it from my custom origin digital ocean droplet?
- There is an AWS tutorial on how to serve dynamic content using ec2
and cloudfront
(https://aws.amazon.com/cloudfront/getting-started/EC2/) but doesn't
go into the detail of configuring the DNS settings and his set up
doesn't cache any content so not sure purpose not caching content in
his tutorial serves?
- If I have 2 origins defined (s3 and digital ocean droplet) and two
alternate name (assets-dev.example.com and dev.example.com) how would
cloudfront know from which origin to serve content from? Note in my
site the url to return assets is defined as
https://assets-dev.example.com/js/test.js etc
The only way I can think of is to set up an origin to be something like content.example.com
and create an new dns record using that name which points to the digital ocean droplet. Then add a CNAME record e.g. dev.example.com which points to the cloudfront distribution. This way users can use dev.example.com
to view the site content via cloudfront.
The only issue I have with the above set up is that anyone can bypass cloudfront by using content.example.com so how would any benefits such cloudfront ddos protect help in this scenario?