搭建博客
如果已经满足部署到github上的条件请跳过
安装hexo
- git
- nodejs
- hexo
这三个是必须的,安装其他教程的安装配置好环境变量之后,输入hexo -v
,我的版本如下
INFO Validating config
hexo: 5.2.0
hexo-cli: 3.1.0
os: Windows_NT 10.0.18363 win32 x64
node: 12.16.1
v8: 7.8.279.23-node.31
uv: 1.34.0
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 72
nghttp2: 1.40.0
napi: 5
llhttp: 2.0.4
http_parser: 2.9.3
openssl: 1.1.1d
cldr: 35.1
icu: 64.2
tz: 2019c
unicode: 12.1
安装好git之后配置好ssh密钥
1 | git config --global user.name "name" |
然后根据你邮箱生成密钥
1 | ssh-keygen -t rsa -C "email@email.email" |
创建博客
创建一个空文件夹,在此处运行gitbash,
1 | hexo init |
…
success Saved lockfile.
Done in 6.88s.
INFO Start blogging with Hexo!
说明下载成功
创建git仓库备份
非必须,后悔药,懂得都懂
新建一个.gitignore
文件,把/public
写进去
本地运行
1 | hexo s |
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
打开的页面就是使用文档,我不再赘述了
服务器
本地: Windows 10
服务器: CentOS 7
安装git
1 | yum insatll -y git |
为了安全,我们新建一个用户叫git
1 | useradd git # 添加用户名为git |
请不要直接复制粘贴进去,因为有前缀,自己手打一遍可以加深印象
建立Git仓库
1 | cd ~ # 到git用户的个人文件夹,默认为/home/git/ |
然后利用钩子函数自动部署
1 | cd blog.git/hooks |
添加以下内容
1 |
|
配置权限
1 | chmod +x post-receive #可执行权限 |
测试
在本地
1 | git clone git@<your_ip_address>:/home/git/repos/blog.git |
换成你的ip即可
若出现
Cloning into ‘blog’…
git@47.100.90.111’s password:
warning: You appear to have cloned an empty repository.
配置完成。
然后建立ssh公钥链接
本地使用Gitbash ,因为Windows的用户文件夹不是~
,而是%HOMEPATH%
,夺麻烦呀,用gitbash可以帮你减少输入量。
1 | ssh-copy-id -i ~/.ssh/id_rsa.pub git@<your_ip_address> # 将本机的公钥复制到服务器中,需要输入一次密码(git用户的密码) |
安全
禁用git用户的shell登录权限,只能使用git clone和git push等命令
1 | which git-shell |
然后
1 | vi /etc/passwd |
1 | - git:x:1000:1000::/home/git:/bin/bash |
中间的数字不是确定的
安装NGINX
1 | yum install nginx # 安装 |
配置
1 | vim /etc/nginx/nginx.conf |
修改用户避免出现权限问题
1 | - user nginx; |
然后重启nginx
1 | # nginx -s reload |
本地修改博客配置
1 | deploy: |
1 | 添加部署插件,若之前安装过可跳过 |
配置https
首先需要配置域名和一份证书,可以使用 Let’s Encrypt 的免费证书或在阿里云等服务商处代为申请。
推荐使用Certbot进行一键HTTPS配置。
1 | yum install certbot |
踩坑记录推荐看这篇:https://blog.csdn.net/w345731923/article/details/105243372
使用nexT主题并优化
以下为我的个人配置
我的版本是7.8.0
<不想弄了>