准备阶段

服务端工具

  • 大前提是你有台服务器
  • optional[域名]
  • nodejs
  • git
  • nginx

服务端预处理阶段

  • 换源(如果对原来的镜像速度不满意的话)
  • 打开服务器端口(80,22)等

相关安装命令

1
2
3
4
5
6
sudo apt update
curl -sL https://deb.nodesource.com/setup_${你想要的版本}.x | sudo -E bash -
---以上安装新的nodejs---
sudo apt install nginx git -y
sudo systemctl enable nginx && sudo systemctl start nginx
---配置没问题的话现在访问IP地址就已经能看到nginx了

本地准备

  • 配置本地hexo工作目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd ${你想要的路径(比如 E:/hexo-blog)}
mkdir ${博客文件夹名}
cd ${文件夹}
hexo init
hexo g;hexo s
npm i hexo-deployer-git --save
npm i hexo-server
修改根目录下_config.yml文件-
deploy:
type: git
repo: git@ip:/home/git/${blog-name}.git
branch: main
--

--本地工作目录初始化完成

搭建

  1. 添加用户git -> server

    1
    2
    adduser git
    adduser git sudo
  2. 切换git用户配置ssh -> server

    1
    2
    3
    4
    5
    6
    su git
    mkdir ~/.ssh
    ssh-keygen --> 一路enter到结束就行
    cp ~/.ssh/id_rsa.pub authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
  3. 如果之前没生成ssh_key 则调用ssh-keygen 生成一份,并将本地的id_rsa.pub文件内容放到server的authorized_keys文件夹末尾(不能覆盖) -> 本地

    1
    2
    ssh-keygen ...
    ssh -v git@server_ip -> 测试是否能访问
  4. 创建空git项目并启用hooks ->

    1
    2
    3
    4
    5
    6
    --git用户
    cd ~
    git init --bare blogs.git
    nvim ~/blogs.git/hooks/post-receive
    通过nvim 添加以下内容至post-receive中
    git --work-tree=${博客路径} --git-dir=/home/git/blog.git checkout -f

    个人建议直接放到/home/git/dirs 下,省了个文件夹授权操作.

    1
    chmod +x ~/blog.git/hooks/post-receive ->赋予可执行权限
  5. 配置nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mkdir /etc/nginx/vhost
nvim /etc/nginx/vhost/blog.conf
添加以下内容
server{
listen 80;
root ${博客路径};
server_name test.top;
location /{
}
}
:wq
nvim /etc/nginx/vhost/httpsblog.conf
server{
listen 80;
root ${blog路径};
server_name www.test.top;
location /{
}
}
1
2
3
4
5
在 /etc/nginx/nginx.conf文件中引入上述自定义配置文件
在http{}中使用include
-> include /etc/nginx/vhost/*.conf;
重启nginx服务看看效果

记得修改nginx 的默认访问文件