0:前置

  • 1.购买服务器
  • 2.本地部署Hexo(如没有本地部署请点击这里跳转到Hexo部署教程)

    0:Hexo配置

  • Hexo 配置

  1. 安装 Git 部署插件

    1
    npm install hexo-deployer-git --save
  2. 修改 _config.yml

    1
    2
    3
    4
    deploy:
    type: git
    repo: ssh://[email protected]:8888/www/wwwroot/hexo.git
    branch: master
  • 注意:这里88.88.88.88改成你的服务器IP,”8888”是SSH 端口。服务器默认ssh端口是22,建议在后台将这个端口更改为其他的
  1. 部署命令
    1
    hexo clean && hexo g && hexo d

0:服务器端配置(SSH 执行)

在你的服务器SSH中执行以下命令,逐行复制并执行:

服务器ssh执行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 创建裸仓库目录
mkdir -p /www/wwwroot/hexo.git
cd /www/wwwroot/hexo.git
git init --bare

# 创建 post-receive 钩子(推送后自动部署到网站目录)
cat > hooks/post-receive << 'EOF'
#!/bin/bash

#这里的"WANGZHAN.com"替换为你自己的网站域名
GIT_WORK_TREE=/www/wwwroot/WANGZHAN.com git checkout -f master
EOF

#增加执行权限
chmod +x hooks/post-receive

# 确保网站目录存在
mkdir -p /www/wwwroot/WANGZHAN.com

#给目录设置权限
chown -R root:root /www/wwwroot/hexo.git
chown -R www:www /www/wwwroot/jiuyiks.cn
chmod -R 755 /www/wwwroot/jiuyiks.cn

登录宝塔面板 → “网站” → “添加网站” → 确保此处网站域名与上方yml中的域名一致

执行Hexo命令生成网站文件

本地 PowerShell 执行:

1
hexo clean && hexo g && hexo d

执行命令后,系统会提示你输入密码(passphrase)。
Enter passphrase (empty for no passphrase):​ →直接回车(留空)
Enter same passphrase again:​ →再次直接回车(留空)

注意:因为你是用来做 Git 自动部署​的。如果设置了密码,每次本地电脑向服务器推送代码时,都会弹窗让你输入密码,过于麻烦

  • 因此,我们需要生成唯一密钥,这样每次执行Hexo命令就无需都进行验证了
  • 配置 SSH 密钥:

本地 PowerShell 执行:
···ssh

生成密钥

ssh-keygen -t ed25519 -C “hexo-deploy”

此处的IP需要与你的服务器一致

ssh-copy-id -p 19193 [email protected]

查看公钥内容

Get-Content “你的密钥路径”

复制输出的内容,SSH 登录服务器后执行:

mkdir -p ~/.ssh
echo “粘贴你复制的公钥内容” >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
```

教程结束,如果在此过程中出现未知错误,可以加入九依的qq群问万能的群友
qq2590678452