云主机linux个人博客安装hugo并配置到nginx

安装配置教程

Posted by kzdgt on Saturday, February 19, 2022

参考:hugo博客部署到腾讯云轻量级服务器 | Sulv’s Blog (sulvblog.cn)云主机linux个人博客安装hugo并配置到nginx_舌尖上的蛋炒饭的博客-CSDN博客

下载hugo

打开hugo的GitHub

下载到云主机

下载

[root@hecs-82454 local]# wget https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_0.88.1_Linux-64bit.tar.gz

解压压缩包

[root@hecs-82454 local]# tar -zxvf hugo_0.88.1_Linux-64bit.tar.gz -C /usr/local/bin
LICENSE
README.md
hugo

生成网站站点

创建博客位置

[root@hecs-82454 bin]# hugo new site myBlog
Congratulations! Your new Hugo site is created in /usr/local/bin/myBlog.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/ or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.
[root@hecs-82454 bin]# 

新的博客是没有主题的,但是hugo没有主题是不能用的

下载主题

hugo主题喜欢的不算多,目前使用的是这个主题,Clean White | Hugo Themes (gohugo.io)

下载地址,或者链接:http://124.222.126.102:6010/share/detail/80b165c5-5925-4fc0-44c1-dcad54cebe0a 提取码:cjby

主题介绍页面有配置和地址介绍,或者按照下面操作

快速创建能跑起来的项目

$ mkdir test
$ cd test
$ mkdir themes
$ cd themes
$ git clone https://github.com/zhaohuabing/hugo-theme-cleanwhite.git
$ cp -r hugo-theme-cleanwhite/exampleSite/** ../
$ cd ..
$ hugo serve

配置主题

配置的话在config.toml页面配置,按需求配置即可

将最上面的这个baseurl替换成你自己的站点,要么域名要么ip+端口,如:

baseurl = "http://124.222.126.102:8090"

生成静态页面

直接执行hugo命令即可,执行完会生成public文件夹

[root@hecs-82454 myBlog]# ./hugo
Start building sites … 
hugo v0.88.1-5BC54738 linux/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:3:7: executing "header" at <partial "header.html" .>: error calling partial: execute of template failed: template: partials/header.html:8:7: executing "partials/header.html" at <partial "header/meta.html" .>: error calling partial: execute of template failed: template: _internal/opengraph.html:37:17: executing "_internal/opengraph.html" at <index $siteSeries ($name | urlize)>: error calling index: index of untyped nil
Total in 176 ms

Nginx下载

官网下载:http://nginx.org/en/download.html 或者直接在linux执行命令:wget http://nginx.org/download/nginx-1.12.2.tar.gz 这里下载的版本是1.12.2

安装步骤

# 安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 解压缩
tar -zxvf linux-nginx-1.12.2.tar.gz
cd nginx-1.12.2/
# 执行配置
./configure
# 编译安装
make
make install

默认安装在**/usr/local/nginx**

防火墙配置

nginx默认监听80端口,你用哪个端口就在服务器控制台打开防火墙端口

配置nginx

   server {
        listen       1314;
        server_name  localhost;
        
        location / {
        root   /usr/local/bin/myBlog/public;
        index  index.html;
    }
}

将上面的内容配置到安装目录nginx.conf里,开放1314端口给博客使用,保存后重新加载nginx服务

[root@hecs-82454 conf]# cd ../sbin
[root@hecs-82454 sbin]# ls
nginx
[root@hecs-82454 sbin]# ./nginx -s reload

注意事项

  • 不会热加载,每次修改内容或配置后,需要重新加载nginx服务。
  • 重启服务器,如果Nginx没有起来,需要手动启动,可以查看进程或者进程id确认。Nginx安装在默认位置 /usr/local/nginx/sbin/nginx
查看进程
ps -ef | grep nginx
查看进程id
ps -C nginx -o pid
启动
 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

「真诚赞赏,手留余香」

kzdgt Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付