How to Add a Subdomain Website on Cloudflare Content Delivery Network

Introduction

Adding a subdomain website on Cloudflare CDN (Content Delivery Network) can significantly improve your site’s performance and security. Cloudflare is a popular CDN service that makes copies of your website content and serves them from data centers around the world, speeding up load times for your visitors.

In this article, we’ll walk through the step-by-step process of setting up a subdomain on Cloudflare CDN.

Prerequisites

Before getting started, make sure you have the following:

  • A Cloudflare account
  • An active domain name registered with a domain name registrar
  • Access to edit the domain name’s DNS records at your registrar
  • A hosting provider or origin web server for your subdomain website content

Step 1: Create a Cloudflare Account

If you don’t already have a Cloudflare account, go to cloudflare.com and click Sign Up. Follow the prompts to create your free Cloudflare account.

Once your account is activated, you can proceed to the next step.

Step 2: Add Your Domain to Cloudflare

In your Cloudflare dashboard, click Add Site and enter your main domain name (e.g. example.com). Cloudflare will detect your domain name’s current DNS settings and provide instructions for changing them to Cloudflare’s nameservers.

Important: This process will involve changing your domain’s nameserver records to direct DNS traffic through Cloudflare’s network. Make sure you have access to edit the domain’s DNS records before proceeding.

Follow the steps provided by Cloudflare to change your domain’s nameservers and verify the domain with Cloudflare. This may take up to 24 hours to fully propagate.

Step 3: Create a CNAME Record for Your Subdomain

Now that your main domain is set up with Cloudflare, it’s time to create a subdomain CNAME record. Here are the steps:

  1. In your Cloudflare dashboard, go to the DNS tab
  2. Click + Add Record
  3. Select CNAME as the record type
  4. Enter your subdomain (e.g. blog) in the Name field
  5. Enter your domain (e.g. example.com) in the Target field
  6. Change the proxy status to Proxied
  7. Click Save

This creates a CNAME record that points your subdomain to your root domain through Cloudflare’s proxy network.

Step 4: Set Up Website Content for Your Subdomain

Your subdomain now exists as a DNS record, but you still need to set up website content for it to serve.

If your main domain is already hosting a website, create a subdirectory on your server to hold your subdomain’s content (e.g. example.com/blog).

If you want your subdomain hosted on a separate server, make sure that server has an A record pointing to its IP address.

In either case, Cloudflare will proxy requests for your subdomain to your origin web server.

Step 5: Enable SSL for the Subdomain (Optional)

If your main domain is using an SSL certificate from Cloudflare, the same certificate will work automatically for first-level subdomains like blog.example.com.

However, you’ll need to install a separate SSL certificate for deeper level subdomains like dev.blog.example.com.

To enable SSL:

  1. Go to the SSL/TLS tab in Cloudflare
  2. Click Create Certificate next to your subdomain
  3. Follow the prompts to activate the certificate

Enabling SSL encrypts traffic between Cloudflare and your origin server.

Advanced Configuration Tips

Here are some advanced tips for further customizing your subdomain setup on Cloudflare:

  • Set up subdomain-specific page rules for caching, security, etc.
  • Redirect your subdomain to a different domain or subfolder
  • Enable Cloudflare Argo Smart Routing for improved performance
  • Use Cloudflare Workers to run serverless scripts that customize responses
  • Set up access policies to restrict who can view the subdomain

See Cloudflare’s documentation for more details.

Conclusion

Adding a subdomain website on Cloudflare CDN provides the optimized performance and security of Cloudflare while allowing you to serve custom content from a subdomain.

In just a few steps, you can have your subdomain running through Cloudflare’s global network without needing to change your existing hosting setup.

As you build out your website, take advantage of all Cloudflare has to offer by exploring features like caching rules, firewall protection, image optimization and more.

I hope this guide has helped explain how to easily add a subdomain website using Cloudflare CDN! Let me know in the comments if you have any other questions.