前提:本文档默认你已经拥有一台公网可以访问的云服务器
云服务的操作系统是 AlmaLinux 9.2
一、Hugo程序安装
Hugo 是一个基于Go 语言的框架,可以通过解析markdown文件快速生成静态页面,从而快速方便的创建属于自己的博客。搭建博客的第一步我们先要下载程序,首先访问Hugo的github地址,进入release页面下载最新的程序安装包即可(我使用的是extends和x64版本)。
1
|
https://github.com/gohugoio/hugo/tags
|


1
2
3
4
|
cd /opt/
wget https://github.com/gohugoio/hugo/releases/download/v0.138.0/hugo_extended_0.138.0_Linux-64bit.tar.gz
tar xf hugo_extended_0.138.0_Linux-64bit.tar.gz
mv hugo /usr/local/bin/
|
二、搭建博客
选择主题的网址:
1
|
https://themes.gohugo.io/
|

1
2
3
4
5
6
7
8
9
|
# 创建一个新的站点
hugo new site mysite
# 添加主题
cd /opt/mysite
git clone https://github.com/CaiJimmy/hugo-theme-stack/ themes/hugo-theme-stack
# 复制主题文件到当前工程
cp -r themes/hugo-theme-stack/exampleSite/content/* content/
rm -f hugo.toml
cp themes/hugo-theme-stack/exampleSite/* ./
|
这里都是一些个性化的配置,随你自己去调整。
三、域名和服务器
在aliyun购买了域名,并进行了备案,然后配置dns解析到自己的云主机。
四、配置反向代理
1
2
3
|
dnf install -y nginx
systemctl start nginx
systemctl enable nginx
|
使用Let’s Encrypt免费申请一个tls的证书(具体的操作百度吧,挺简单的)。然后编译安装nginx(其实你也可以二进制安装)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
server {
listen 443 ssl http2;
listen [::]:443 http2;
ssl_certificate /data/h2c.tech.crt;
ssl_certificate_key /data/h2c.tech.key;
server_name h2c.tech;
index index.html index.htm;
error_page 400 = /400.html;
location /
{
proxy_redirect off;
proxy_pass http://127.0.0.1:1313;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
|
五、启动Hugo
配置文件修改相关参数,然后只执行hugo server &也行
1
|
hugo server --config /srv/hugo-server/mysite/hugo.yaml -p 1313 --baseUrl=https://blog.tqg.me
|