Cloudflare is a DNS management service and content delivery network (CDN). Ghost(Pro) users commonly route their DNS through Cloudflare for its support of root level CNAMEs and flexible redirects, known as page rules.

The following steps will walk you through how to setup a root domain or subdomain with your Ghost(Pro) publication, using Cloudflare to manage your domain's DNS records.

Connect Your Domain to Cloudflare

The first step for both types of configuration is to create a free Cloudflare account and follow a few steps. There are paid options available but you only need a free account to setup a custom domain with Ghost.

Enter your domain name when creating your new Cloudflare account and it will query your existing DNS records and port them over. Review these records and port any over that are required.

Update your Nameserver (NS) with your domain provider to the NS records that Cloudflare requests during the setup process. If you're unsure where to update this you may need to contact your domain provider directly:

Update Nameservers

When your Cloudflare Overview shows a status of "Active" you are ready to configure your domain's DNS to point to your Ghost(Pro) publication - this can take a few minutes:

Active Status

Root domain vs subdomain

A subdomain can be described as a division or "alias" of your custom domain. For example, a subdomain of yourdomain.com could be set to www.yourdomain.com or blog.yourdomain.com – both www and blog are considered the "subdomains".

A root domain, or "naked' domain, does not include any subdomains, for example yourdomain.com.

Whether you use a root domain or subdomain with your publication is a matter of personal preference, however there are different setup steps for each that must be followed.

To use a root domain with your publication (e.g. yourdomain.com ), follow steps in the root domain setup guide.

To use a subdomain with your publication (e.g. www.yourdomain.com ), follow the steps in the subdomain setup guide.

Root domain setup

To configure your DNS records for a root domain, navigate to the DNS settings area of your Cloudflare dashboard and add a CNAME record type:

Add CNAME

In the "Name" field, enter @ for a root domain configuration. This uses yourdomain.com as the default custom domain for your Ghost(Pro) publication.

In the IPv4 address, enter the ghost.io URL for your publication, <subdomain>.ghost.io and add your new CNAME record:

CNAME Record

Redirecting the www subdomain to the root domain

To ensure your publication does not return 404 errors when visitors visit the site with and without the www subdomain, create a second CNAME record for www and point it to yourdomain.com:

Add Page Rules

Page rules in Cloudflare are custom redirect patterns which can be used to prevent your visitors navigating to the wrong URL. For a root domain setup, you need to redirect visitors who arrive on a subdomain to your root domain.

Create a page rule to redirect the subdomain traffic to your root domain, setting the URL pattern to www.yourdomain.com/*

Set the destination URL option to use "Forwarding URL".

Set the status code as "301 - Permanent Redirect":

In the destination URL field, enter the following URL pattern: https://yourdomain.com/$1

Once your Page Rule is saved and deployed, all traffic to https://www.yourdomain.com and http://www.yourdomain.com will be redirected to https://yourdomain.com.

Subdomain setup

To configure your DNS records for a subdomain, navigate to the DNS settings area of your Cloudflare dashboard and add a CNAME record type:

Add CNAME

In the "Name" field, enter your desired subdomain configuration, in this example we'll use www which makes www.yourdomain.com the default custom domain.

In the IPv4 address, enter the ghost.io URL for your publication, <subdomain>.ghost.io and add your new CNAME record:

Redirecting the root to the subdomain

To ensure your publication does not return 404 errors when readers visit your site without the www subdomain, create a second CNAME record for @ and point it to www.yourdomain.com:

Add page rules

Page rules in Cloudflare are custom redirect patterns which can be used to prevent your visitors navigating to the wrong URL. For a subdomain setup, you need to redirect visitors who arrive on your root domain to your subdomain.

Create a page rule to redirect the root domain traffic to your subdomain, setting the URL pattern to yourdomain.com/*

Set the destination URL option to use "Forwarding URL":

Set the status code as "301 - Permanent Redirect":

In the destination URL field, enter https://www.yourdomain.com/$1

Once your Page Rule is saved and deployed, all traffic to https://yourdomain.com and http://yourdomain.com will be redirected to https://www.yourdomain.com. Follow the steps below to activate your domain and complete the process.

Domain Activation

The final step to complete your custom domain setup is to go back to Ghost.org and activate your custom domain.

  • Log into your Ghost.org account at my.ghost.org/signin and setup a custom domain in the "Domain Settings" section.

  • Enter the domain into the custom domain field on my.ghost.org, making sure to include www for a subdomain setup, OR, excluding www for a root domain setup.

Activate Custom Domain

  • Activate your custom domain - this can take anywhere from a few seconds to a few hours due to the length of time your DNS takes to propagate.

  • Once activated, you can view your publication by going to the custom domain directly from the browser.

Summary

Great work! 🤓 You successfully setup a root domain and a subdomain redirect with your Ghost(Pro) publication through Cloudflare. Regardless of how a user enters your publication's URL in their browser, they'll always be directed to the correct site.

If you're having trouble getting your custom domain to activate, drop [email protected] a message for help.