How to build a website using Hugo static site generator

This website is built with the Hugo static site generator.

Install

On macOS

brew install hugo

Create deployment script

On local computer

cd $HUGO_REPO

cat <<EOF >> ./deploy.sh
#!/bin/sh

USER=pieter
HOST=host.example.org
DIR=/var/www/website/

hugo && rsync -avz --delete public/ \${USER}@\${HOST}:\${DIR}

exit 0
EOF

chmod +x deploy.sh

On server

export WEBSITE_DOMAIN="pieterhollander.nl"
export USER="pieter"

sudo mkdir -p /var/www/website

sudo chown -R ${USER}:www-data /var/www/website

sudo systemctl stop nginx

sudo certbot certonly --standalone -d ${WEBSITE_DOMAIN}

sudo tee /etc/nginx/conf.d/${WEBSITE_DOMAIN}.conf << EOF
server {
    listen 80;
    listen [::]:80;
    server_name ${WEBSITE_DOMAIN};

    location / {
        return 301 https://\$server_name\$request_uri;
    }

}

server {
    server_name ${WEBSITE_DOMAIN};
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/letsencrypt/live/${WEBSITE_DOMAIN}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${WEBSITE_DOMAIN}/privkey.pem;
    ssl_dhparam /etc/ssl/certs/dhparam_4096.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_ecdh_curve secp384r1;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 127.0.0.1 [::1] valid=300s;
    resolver_timeout 5s;
    add_header X-Content-Type-Options nosniff;
#    add_header Strict-Transport-Security "max-age=63072000; preload";
    keepalive_timeout 300s;

    location / {
        root   /var/www/website;
        index  index.html index.htm;
    }

}
EOF

sudo nginx -t

sudo systemctl restart nginx

On local pc

cd $HUGO_REPO
./deploy.sh