Cloudflare is a DNS management service and content delivery network (CDN). Ghost(Pro) users commonly route their DNS through Cloudflare for it's 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 with your Ghost(Pro) publication, using Cloudflare to manage your domain's DNS records.

Connect Your Domain to Cloudflare

The first step 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

Configure your DNS records

The next step is to configure your DNS records for your domain in Cloudflare.

  • Navigate to your domain in Cloudflare 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 A Page Rule

Page Rules in Cloudflare are custom redirect patterns which can be used to redirect the www subdomain to the root domain.

  • Create a page rule and enter the following URL pattern: *yourdomain.com/*.
  • Set the destination URL to "Fowarding URL":
  • Set the status code as "301 - Permanent Redirect":
  • In the destination URL field, enter the following URL pattern: https://yourdomain.com/$2

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

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 when entering the domain. For example, www.yourdomain.com:

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 support@ghost.org a message for help.