Custom Domain with Digital Ocean Spaces using Cloudflare for DNS

Recently I started using digitalocean spaces for serving static contents. Which is an S3-compatible object storage service.

They do provide a mechanism to point a custom domain to a spaces instance with their CDN options. However for that the domain should be managed by Digitalocean. Since i was already using Cloudflare for my DNS that doesn't work.

I searched for a way to achieve that, and this digitalocean community answer was the only thing i could find. So i thought i will lay down the steps to point a Custom Domain to Digitalocean Spaces while using Cloudflare for DNS.

1. Create Digitalocean Spaces Instance

Go to Digitalocean Dashboard and create a new Spaces instance
create-space-dropdown
Select a region and dont forget to enable CDN
create-space-dialog
Click "Add a new Subdomain Certificate"
enable-cdn
Select "Bring your own certificate"
add-custom-subdomain

2. Generate Origin Server SSL Certificate from Cloudflare

Go to SSL/TLS in Cloudflare and select Origin Server
origin-server-1
Click "Create Certificate" and select "Let Cloudflare generate a private key and a CSR" with RSA as an option. Also add the custom domain you want.
create-certificate
Clicking "next" you will be shown "Certificate" and "Private key". Use this to fill the Custom Subdomain form in Step 1.
filled-custom-subdomain

3. Add CNAME record to Cloudflare

After adding the Certificate and Private Key, it will show the details to add CNAME record. For example in this case the domain given was example.sgp1.digitaloceanspaces.com

Now go back to Cloudflare Dashboard and Add the CNAME record to the given domain.
cname-record

That was it. Now you would be able to use your custom domain with the Digitalocean Space.

Hope this helps  anyone looking to implement this. Thanks.

Show Comments