Report this

What is the reason for this report?

How to setup CDN on Digital Ocean?

Posted on June 26, 2025

Hi everyone,

I am trying to set up a Content Delivery Network (CDN) on DigitalOcean to improve the performance and global delivery speed of my website, but I’m not entirely sure about the correct configuration steps.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey Prakash! 👋

If you’re using DigitalOcean Spaces, setting up a CDN is super easy:

  1. Head over to the Spaces dashboard and create a new Space (basically a storage bucket).

  2. While creating it, check the “Enable CDN” option, this gives you a CDN endpoint like https://your-space-name.nyc3.cdn.digitaloceanspaces.com.

  3. Upload your static files (images, CSS, JS, etc.) to that Space.

  4. Use the CDN URL in your website to load those assets faster from edge locations around the world.

  5. Point a custom domain (like cdn.yoursite.com) to that CDN endpoint using a CNAME record, then enable SSL.

Docs here if you want to dig in:

https://docs.digitalocean.com/products/spaces/how-to/enable-cdn/

If you’re self-hosting on a Droplet, you can also put Cloudflare in front of it for full-site CDN and DDoS protection.

- Bobby

Heya,

bsolutely—let’s walk step by step through setting up a CDN on DigitalOcean to accelerate your website’s content delivery.

DigitalOcean’s Spaces product has built-in CDN support via their integration with the DigitalOcean CDN (backed by Fastly).

I’ll guide you through configuring a CDN for your Spaces bucket, which is the most common approach (though you can also put a CDN in front of your Droplets if needed).

Step 1: Create a Space

If you haven’t already:

  1. Log in to your DigitalOcean Control Panel.

  2. In the left menu, click Spaces.

  3. Click Create a Space.

  4. Choose:

    • Datacenter region nearest to most of your visitors.

    • Enable CDN option (or you can enable it afterward).

    • Set permissions (public or private).

  5. Click Create a Space.

Tip: For CDN delivery, files typically need to be public.


Step 2: Enable the CDN

If you didn’t enable CDN at creation time:

  1. Go to your Space in the DigitalOcean dashboard.

  2. Click the Settings tab.

  3. Find the CDN section.

  4. Click Enable CDN.

  5. Optionally, add a custom subdomain (e.g., cdn.yourdomain.com) by:

    • Entering the subdomain.

    • Verifying ownership (you’ll get a CNAME record to set in your DNS).

    • After propagation, DigitalOcean provides an SSL certificate automatically.

When enabled, you’ll see a CDN endpoint URL (e.g., https://your-space.nyc3.cdn.digitaloceanspaces.com).


Step 3: Upload Your Website Assets

  • Use the Spaces web console, s3cmd, rclone, or the AWS S3-compatible API to upload images, videos, CSS, JS, etc.

  • Make sure objects are public for the CDN to serve them.

Step 4: Update Your Website URLs

Update your website so static assets point to the CDN endpoint or your custom subdomain. For example:

<img src="https://cdn.yourdomain.com/images/logo.png" />

or

<link rel="stylesheet" href="https://your-space.nyc3.cdn.digitaloceanspaces.com/css/styles.css" />

Step 5: Configure Caching and Headers (Optional)

You can fine-tune cache behavior:

  • Use Cache-Control headers on your files (e.g., max-age=31536000 for one year).

  • You can set default cache settings in the Settings > CDN tab.

Alternative: CDN in front of Droplet

If you prefer to put a CDN in front of your Droplet (origin server) rather than Spaces:

  • Use Cloudflare, Fastly, or DigitalOcean Load Balancers with Cloudflare.

  • You configure your DNS to point to the CDN provider, which fetches content from your Droplet.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.