Jürgen's Notebook

I use Hugo together with the Doks theme to create this website.

Install Hugo

You can install Hugo on your server. But since Hugo creates purely static web contents, I installed on my Linux laptop which runs Ubuntu. For Ubuntu, Hugo maintains newer versions only as a snap package. So in to do the installation just call:

Install Hugo
sudo snap install hugo

Initial Setup of the Website

Note

Visit Hugo Quick Start and Doks Documentation for a detailed introduction.

In your home directory you can create a new directory, e.g. src, if you do not already have it. Then move in this directory.

Create src Directory
mkdir ~/src
cd ~/src

To create a new site with the Doks theme enabled, just follow the instructions on Installation.

With the command pnpm dev a webserver is started. Open http://localhost:1313 with your web browser to see your website. With CTRL+C you can stop the webserver.

Simply calling pnpm build will create a static version of the website in the folder ~/src/<your_site_name>/public. This folder will later be used by Caddy to provide the website to your audience.

Deploying the Website

To deploy the website, the contents of the public directory needs to be copied to your server. I recommend to create on server side a directory under the existing /usr/share/caddy folder:

On your server, execute:

Create Website Directory
sudo mkdir /usr/share/caddy/<your_site_name>
sudo chmod 777 /usr/share/caddy/<your_site_name>

The tool rsync can be used to publish the website. I created a script deploy.sh that does this and can be executed on my laptop:

deploy.sh
#!/bin/bash

set +x

# build the site
pnpm build
# copy over the site to the server
rsync -v --delete --recursive ./public/ <your_server>:/usr/share/caddy/<your_site_name>/

Caddy Setup

The static website content is now available in the directory /usr/share/caddy/<your_site_name>. I assume you have created the domain website.example.com that can be used for providing the website on the internet.

Note

For a detailed documentation pleaser refer to the Caddy website.

Caution

In the Caddyfile always use TABs to indent statements. Spaces will cause format errors.

Now you need to add following lines in the file /etc/caddy/Caddyfile:

/etc/caddy/Caddyfile
website.example.com {
	root * /usr/share/caddy/<your_site_name>
	file_server
}

With following commands Caddy will read the new configuration and you can check for the status:

Reload Caddyfile
cd /etc/caddy
sudo caddy reload
sudo service caddy status

Caddy will serve the contents in /usr/share/caddy/<your_site_name> as website with the address https://website.example.com. An SSL certificate will be assigned and updated automatically.