Here we're going to build secure https website by using Hugo, Nginx, and Cerbot(Let's Encrypt).

Hugo

Install

In most distributions of Linux we can just use one command to install hugo, take examples here for Debian/Unbuntu and Arch Linux here

1
2
3
4
5
# Debian and Ubuntu
sudo apt install hugo

# Arch Linux
sudo pacman -S hugo

For more details: https://gohugo.io/getting-started/installing/

Build the first new site

After installing Hugo, then we can use the following command to build a new site quickly

1
hugo new site mywebsite

The the new site name mywebsite can be replaced with any name we like.

Init git repository

One of the advantages of Hugo is that we can use git for version control and migration.

1
2
3
4
5
6
cd mywebsite
git init
git add .
git commit -m 'init'
git remote add origin git@gitee.com:xxx/mywebsite.git
git push -u origin main

Themes

We can find many themes from https://themes.gohugo.io/. One of the easiest ways of getting themes is using git. And here we're going to use git to clone the theme even from github the the sub folder themes/even.

1
2
git clone --depth=1 https://github.com/olOwOlo/hugo-theme-even themes/even
rm -rf themes/even/.git

Most themes provide example of site config file config.toml, we can just make modification based on the example.

1
cp themes/even/exampleSite/config.toml ./

Add a new post

Hugo provides a command to create a new post under the folder content, by the way the command should be executed under the hugo site folder.

1
hugo new post/first.md

Preview with local server

We can use the command below to start a local sever and open the address http://localhost:1313 to preview the posts

1
hugo server

Generate static pages

We can also execute hugo=(without any params) to generate static pages under folder =public

1
hugo

Nginx

Install

1
sudo apt install nginx

Set hugo folder public as nginx server root.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
server {
    listen    80;
    server_name    www.mywebsite.cn;
    return 301 $scheme://mywebsite.cn$request_uri;  
}

server {    
    listen  80;
    server_name mywebsite.cn;
    access_log  /home/xxx/space/doc/mywebsite.cn/log/access.log.gz combined gzip; 
    error_log /home/xxx/space/doc/mywebsite.cn/log/error.log;   
    client_max_body_size 20M;   
    location / {       
        index   index.html;                
        root    /home/xxx/mywebsite.cn/public;    
    }                                                                                
    location ~ /\.ht {                                                         
        deny all;                                                               
    }                                                                          
}

Cerbot (Let's encrypt)

Install snap

1
2
sudo apt install snap
sudo snap install core; sudo snap refresh core

Install cerbot

1
2
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

Add new cert

1
sudo certbot --nginx