Contents

Deploying Your Hugo Blog to Cloudflare Pages

If you’re an engineer who loves to write about your craft, you’ve probably considered starting a blog. And if you’ve been looking for a way to deploy your Hugo blog to the cloud, look no further than Cloudflare Pages.

In this article, we’ll walk you through the steps required to deploy your Hugo blog to Cloudflare Pages. It’s an easy process that won’t take more than a few minutes, and the best part is that it’s completely free!

What is Hugo?

Before we get started, let’s briefly touch on what Hugo is. Hugo is a static site generator that allows you to create your own website or blog. It’s fast, efficient, and requires no database or server-side scripting. Hugo generates static HTML files that can be easily deployed to a web server or CDN.

What is Cloudflare Pages?

Cloudflare Pages is a free, fast, and secure way to deploy your Hugo blog to the cloud. It allows you to host your static site and serve it from the edge of the Cloudflare network. This means that your site will load quickly, regardless of where your readers are located.

Getting Started

To get started, you’ll need a few things:

  • A Hugo blog
  • A Cloudflare account
  • A GitHub account

If you don’t have a Hugo blog yet, head over to the Hugo article to get started.

If you don’t have a Cloudflare account, you can sign up for free at Cloudflare.com. Once you’ve created your account, you’ll need to create a new site on Cloudflare Pages.

If you don’t have a GitHub account, head over to GitHub.com and sign up for free. You’ll need a GitHub account to connect your repository to Cloudflare Pages.

Connecting Your Repository

Once you’ve created your site on Cloudflare Pages, you’ll need to connect it to your Hugo repository on GitHub. Here’s how to do it:

  1. Click on the “New Site from Git” button on your Cloudflare Pages dashboard.
  2. Select your Git provider (in this case, GitHub) and click “Continue.”
  3. Follow the instructions to authorize Cloudflare Pages to access your GitHub account.
  4. Select the repository that contains your Hugo blog and click “Continue.”
  5. Choose the branch you want to deploy and configure your build settings.
  6. Click “Save and Deploy” to deploy your site.
  7. Configuring Your Build Settings

Before you can deploy your site, you’ll need to configure your build settings. Here’s how to do it:

  1. Click on the “Build settings” tab on your Cloudflare Pages dashboard.
  2. Add the following build command: “hugo –minify”
  3. Set your build output directory to “public/”
  4. Click “Save” to save your build settings.
  5. Deploying Your Site

Once you’ve connected your repository and configured your build settings, you’re ready to deploy your site. Here’s how to do it:

  1. Click on the “Deployments” tab on your Cloudflare Pages dashboard.
  2. Click on the “Deploy” button to deploy your site.
  3. Wait for Cloudflare Pages to build and deploy your site. This process may take a few minutes.

Once your site is deployed, you can access it by clicking on the “Live Site” button on your Cloudflare Pages dashboard. Also, you can enable automatic deploy on any changes of your GitHub repo.

Add Your Own Domain Name

  1. Purchase a domain name from a domain registrar of your choice (e.g., Namecheap, GoDaddy).
  2. Log in to your Cloudflare account and select your site on Cloudflare Pages.
  3. Click on the “Custom Domains” tab and add your domain name.
  4. Follow the instructions to verify ownership of your domain and configure DNS settings.
  5. Once you’ve verified ownership and configured DNS settings, your site will be available at your custom domain.

It’s important to note that different domain registrars have different procedures for configuring DNS settings, but here’s an example:

Let’s assume that your domain name is “example.com” and you want to point it to your Hugo blog on Cloudflare Pages.

  1. Log in to your domain registrar account (e.g., Namecheap, GoDaddy) and find the DNS settings for your domain.
  2. Add a new DNS record for your domain. Choose “CNAME” as the record type and set the name to “www”. Set the value to your Cloudflare Pages subdomain, which will look something like “your-site-name.pages.dev”.
  3. Add another DNS record, this time with the record type “ALIAS” or “ANAME”. Set the name to your root domain (i.e., “@”) and the value to the hostname of your Cloudflare Pages subdomain (e.g., “your-site-name.pages.dev.”). If your domain registrar doesn’t support ALIAS or ANAME records, you can use an A record with the IP address of your Cloudflare Pages subdomain, which you can find in your Cloudflare Pages settings.
  4. Save your DNS settings and wait for the changes to propagate (usually takes a few minutes to a few hours).
  5. Once your DNS changes have propagated, you should be able to access your Hugo blog on Cloudflare Pages using your custom domain name (e.g., “example.com” or “www.example.com”).

After adding your custom domain name, you may want to set up HTTPS encryption. Cloudflare Pages provides free SSL/TLS certificates for all custom domains, so you can easily enable HTTPS encryption by selecting the “Secure” option under the “Custom Domains” tab.

With your custom domain name set up, your Hugo blog on Cloudflare Pages is ready to go live with your own unique web address.

Conclusion

Deploying your Hugo blog to Cloudflare Pages is an easy and free process that allows you to host your site on the cloud and serve it from the edge of the Cloudflare network. With just a few clicks, you can have your blog up and running in no time. So what are you waiting for? Give it a try and start