hugo/content/en/hosting-and-deployment/hosting-on-keycdn.md
Bjørn Erik Pedersen 83bef6955e Squashed 'docs/' changes from 896bad9f4..e161ea09d
e161ea09d Add one more Chinese file to workaround reflect: Zero(nil)
b595b3a21 Add more Chinese translation
56e4e95d9 Use lang.Merge to "fill in the gaps" for untranslated pages
ef079406c Merge commit '650fac3a4e7d256f4505402ab44cfc3c804b8dea'
650fac3a4 Squashed 'themes/gohugoioTheme/' changes from a1768ebb..f31a3dc8
322eff899 Add Chinese language for menus
d90b886e0 Fix Markdown table syntax in previous commit
737f3dfca Update the leaf bundle vs branch bundle table
09fa1bc4e Clarify that `.Now` is obsolete
879ea3f6a Make release notes somewhat more consistent
0113e2051 Move 0.40.2-relnotes into content/en/news
77578f5bf Move content/ into new contentDir content/en/
4dcf7c709 Fix "reflect: Zero(nil)" error in showcase
63dd25505 Release 0.40.2
2076c0d56 releaser: Prepare repository for 0.41-DEV
070fe565e releaser: Add release notes to /docs for release of 0.40.2
4ce52e913 releaser: Bump versions for release of 0.40.2
41907c487 Fix typos in syntax-highlighting.md
91753ef3d Add missing backtick
b77274301 Remove duplicate release notes (0.27, 0.27.1, 0.35)
6e00da316 Remove obsolete content/release-notes/ directory
00a6d8c02 Change en dash back to `--` in 0.38.2-relnotes
51b32dc00 Update archetypes.md
d0e5c2307 Release 0.40.1
4538a6d5b releaser: Prepare repository for 0.41-DEV
91b391d70 releaser: Add release notes to /docs for release of 0.40.1
e0979d143 releaser: Bump versions for release of 0.40.1
7983967c2 Clean images
fe3fdd77d Polish showcase for Flesland Flis
e6dde3989 Showcase - Flesland Flis AS by Absoluttweb
73aa62290 Revive @spf13's special Hugo font
add67b335 Release Hugo 0.40
c0a26e5a6 Merge branch 'temp40'
beeabaaae releaser: Prepare repository for 0.41-DEV
e67d5e985 releaser: Add release notes to /docs for release of 0.40
6cdd95273 releaser: Bump versions for release of 0.40
bee21fb9b Revive the other Hugo logos too
4f45e8fe1 Fix the link type attribute for RSS in examples
8c67dc89a Fix example in delimit doc
e7f6c00d5 Revive the logo used on the forum
82b0cd26e Merge commit 'a215abf70e018f4bf40d6c09d8bd148d8684b33d'
119c8ca58 Merge commit 'd2ec1a06df8ab6b17ad05cb008d5701b40327d47'
db4683bd2 Improve .Get docs
05260b886 .Get function: fix syntax signature

git-subtree-dir: docs
git-subtree-split: e161ea09d33e3199f4998e4d2e9068d5a850f042
2018-05-04 09:44:21 +02:00

94 lines
4.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Hosting on KeyCDN"
date: 2017-09-12
description: "Accelerate your Hugo site globally with a KeyCDN integration. This tutorial shows you how to setup your static site as a GitLab page behind a KeyCDN pull zone."
categories: [hosting and deployment]
keywords: [keycdn,hosting,deployment,cdn]
menu:
docs:
parent: "hosting-and-deployment"
weight: 40
slug: ""
aliases: []
toc: false
draft: false
---
[KeyCDN](https://www.keycdn.com/) provides a multitude of features to help accelerate and secure your Hugo site globally including Brotli compression, Let's Encrypt support, Origin Shield, and more.
## Assumptions
- You already have a Hugo page configured
- You have a GitLab account
- You have a KeyCDN account
## Create a KeyCDN Pull Zone
The first step will be to login to your KeyCDN account and create a new zone. Name this whatever you like and select the [Pull Zone](https://www.keycdn.com/support/create-a-pull-zone/) option. As for the origin URL, your site will be running on [GitLab Pages](https://docs.gitlab.com/ee/user/project/pages/getting_started_part_one.html) with a URL of `https://youruser.gitlab.io/reponame/`. Use this as the Origin URL.
![Screenshot of KeyCDN's pull zone creation page](/images/hosting-and-deployment/hosting-on-keycdn/keycdn-pull-zone.png)
While the origin location doesnt exist yet, you will need to use your new Zone URL address (or [Zonealias](https://www.keycdn.com/support/create-a-zonealias/)) in the `.gitlab-ci.yml` file that will be uploaded to your GitLab project.
Ensure that you use your Zone URL or Zonealias as the `BASEURL` variable in the example below. This will be the user-visible website address.
## Configure Your .gitlab-ci.yml File
Your `.gitlab-ci.yml` file should look similar to the example below. Be sure to modify any variables that are specific to your setup.
```
image: alpine:latest
variables:
BASEURL: "https://cipull-7bb7.kxcdn.com/"
HUGO_VERSION: "0.26"
HUGO_CHECKSUM: "67e4ba5ec2a02c8164b6846e30a17cc765b0165a5b183d5e480149baf54e1a50"
KEYCDN_ZONE_ID: "75544"
before_script:
- apk update
- apk add curl
pages:
stage: deploy
script:
- apk add git
- git submodule update --init
- curl -sSL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz -o /tmp/hugo.tar.gz
- echo "${HUGO_CHECKSUM} /tmp/hugo.tar.gz" | sha256sum -c
- tar xf /tmp/hugo.tar.gz hugo -C /tmp/ && cp /tmp/hugo /usr/bin
- hugo --baseURL ${BASEURL}
- curl "https://api.keycdn.com/zones/purge/${KEYCDN_ZONE_ID}.json" -u "${KEYCDN_API_KEY}:"
artifacts:
paths:
- public
only:
- master
```
Using this integration method, you will have to specify the Zone ID and your [KeyCDN API](https://www.keycdn.com/api) key as secret variables. To do this, navigate to the top-left menu bar in GitLab and select Projects. Then, select your project and click on the Settings page. Finally, select Pipelines from the sub-menu and scroll down to the Secret Variable section.
The Secret Variable for your Zone ID should look similar to:
![Screenshot of setting the Zone ID secret variable](/images/hosting-and-deployment/hosting-on-keycdn/secret-zone-id.png)
While the Secret Variable for your API Key will look similar to:
![Screenshot of setting the API Key secret variable](/images/hosting-and-deployment/hosting-on-keycdn/secret-api-key.png)
The Zone ID and API key are used to purge your zone its not strictly needed but otherwise, the CDN might deliver older versions of your assets for quite a while.
## Push Your Changes to GitLab
Now its time to push the newly created repository to GitLab:
```
git remote add origin git@gitlab.com:youruser/ciexample.git
git push -u origin master
```
You can watch the progress and CI job output in your Gitlab project under “Pipelines”.
After verifying your CI job ran without issues, first check that your GitLab page shows up under `https://youruser.gitlab.io/reponame/` (it might look broken depending on your browser settings as all links point to your KeyCDN zone dont worry about that) and then by heading to whatever Zonealias / Zone URL you defined.
To learn more about Hugo hosting options with KeyCDN, check out the complete [Hugo hosting with KeyCDN integration guide](https://www.keycdn.com/support/hugo-hosting/).