hugo/content/en/hosting-and-deployment/hosting-on-keycdn.md

95 lines
4.3 KiB
Markdown
Raw Normal View History

---
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]
Squashed 'docs/' changes from 3e663efb2..fc61378a3 fc61378a3 Add Hugo 0.32 related docs 77edf7fd7 commands: Regenerate af9d25458 Fix Blackfriday's Markdown extension name 1223dd63a Remove roadmap b8bcb2fb8 Include note to allow hugo write permissions outside home dir 7dbccb936 Fix typo in roadmap 3a38da6f5 Fix spelling 94ebe50ff Merge branch 'master' of github.com:gohugoio/hugoDocs 89376e21d Clarify Hugo Roadmap 03d191fec Mention Reverse function in taxonomy tpl page. a4ea3402d Fix ref and relref function pages. b36632b31 Remove non-existing source variable a638160dc Update Content Organization to match the world 47eb431ca Correct one link in templates/output-formats.md 8bf933629 Spell fix ce2d48728 Add docs for .AllTranslations de94b4942 Move sponsor data to theme data 41fe75254 Merge commit 'f463ef99ed2862e4042557e28aece7ca858e1d0a' f463ef99e Squashed 'themes/gohugoioTheme/' changes from bc851da9..75da2f6b 532c65f2a Move sponsor logo to theme 899e2defe Add sponsor logos to home page and footer 3ca53db97 Release 0.31.1 bb9876ce2 Merge branch 'temp0311' c7c3ee7e5 releaser: Prepare repository for 0.32-DEV 4ac554792 releaser: Add release notes to /docs for release of 0.31.1 52bfb5c15 releaser: Bump versions for release of 0.31.1 cfdc2e4ea Fix output formats example 5746c10c2 More on output format de2ee0fe0 Improve suffix redefinition example c9997839e Update gitlab CI submodule management 82d74e306 Add Bootstrap styling to breadcrumb example c8c9601a8 Use the code shortcode for the breadcrumb example 16be43e7d Clean up formatting in variable definition lists 149c2c157 Add nested section docs 783c3d636 Sync theme 60a220bbd Squashed 'themes/gohugoioTheme/' changes from 6b632895..bc851da9 4b33a04d0 Fix typo 94cffc43c Fix little typo a5d4f762f Fix typo 36c5a0b43 Add a note about the 2 in staticDir2 087bd9a9f Add KeyCDN to menu 4ac8aae38 Hugo 0.31 Released 8fdd995e7 releaser: Prepare repository for 0.32-DEV eb0f38fbb releaser: Add release notes to /docs for release of 0.31 60efdfff7 releaser: Bump versions for release of 0.31 44dafb10b Merge commit '30c0d485eaff6d70df1be0353911ddca485d52bf' e6b847b95 Merge commit '05e42bc643f1840ed2ad9c2eff82a269d1381683' 15d86a525 Handle Taxonomy permalinks 5c3c18d7f Add support for height argument to figure shortcode git-subtree-dir: docs git-subtree-split: fc61378a3227c14883a2942d67c806014e7bb6cb
2017-12-30 03:15:31 -05:00
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
Squashed 'docs/' changes from 2fc775dec..f97826a17 f97826a17 Merge commit '12ecbf4a1b05c2794281f47909c836b1a005bc19' 12ecbf4a1 Squashed 'themes/gohugoioTheme/' changes from ecad8247..fe71e360 aaa7ac214 Ignore .DS_Store files 0e023ca12 Remove comments in showcase front matter f3ba5ac87 Hartwell Insurance showcase 47aefdbda Remove unnecessary duplicated words 612693b4f Some minor language fixes a833ba15b Spelling 5972e70a9 Revert "showcase: Even smaller file" 3479b975e showcase: Even smaller file 2272e0b83 showcase: Reduce image size 718c3c3e5 Spelling 0b954eccb showcase: Pace copy-edits baded8064 showcase: Pace 842c1cedf Add a Showcase copyright notice c5963edaa Update installing 4fa0b0d73 Add link to showcase template d0f303916 Add some showcase guide content c809789b1 Add srcset to the showcase screenshots 49d875904 Start of a template 1153de221 Clean resouerces 69f00df4c Remove the showcases 653ad5bcd Add a simple byline c5342b5e5 Regenerate image after rebase b80669b34 Bump version in config.toml cd5c79c67 Fix an issue where whitespace wrap caused scrollbars on some browsers f00547e98 Add section to the title element aa10defed Iterating on Showcase (#330) 76a0bfbc3 Add some dummy content to some of the showcase pages 66f68964d Standardize showcase metadata 627ffa6d4 Adjust showcase image size on front page cbc3efece Redo some showcase images 054b54cb6 Use .RelPermalink and not .URL 82ba5f1c6 Add resources d1415795b Move showcase items in list view to a template in the layout f34620e90 Tweak details box for mobile df6a0bf24 Include images that changed from the column shift 02036581f Improve showcase single layout 5f7730c89 Improve styling of showcase prev/next buttons a2b2f7731 Remove extra div that was breaking mobile layout of the showcase b172fe5f4 Add block class to to images on mobile so they behave as expected a4ebfec86 Add a proper RSS feed to home page 0524479e0 Move showcase images to proper Resources 0544b57df Convert showcase pages to bundles 8febaab2b Add Showcase to Home page and internal pages 26d1f4542 Fix baseURL in Netlify deploy previews 046497616 Revert "Try to fix the Netlify preview baseURL setup" 80dce17ca Revert "Add some temporary baseURL debug" 8617e8692 Add some temporary baseURL debug 371e56bce Try to fix the Netlify preview baseURL setup 1b70b3f18 Add Netlify CMS to Frontends list d6184e71d Fix menu for "What is Hugo" page 1ae83ad3e Fix mobile menu display so it shows on mid-size displays f60e1f750 Edited slight typo, added "of" 56b906667 Fix typo c5bea5cbd Release 0.36 00539094e releaser: Prepare repository for 0.37-DEV b222cbdf2 releaser: Add release notes to /docs for release of 0.36 e59d1d766 releaser: Bump versions for release of 0.36 9620aa002 docs: Add documentation for smart cropping etc. 91c3801f1 Merge commit 'c305e44f5f081e4436195923a4593e396f07cd49' 8e71ff60b releaser: Prepare repository for 0.36-DEV git-subtree-dir: docs git-subtree-split: f97826a17209fe3e153b7f5bbf69c511e4e13203
2018-02-10 06:51:31 -05:00
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/).