轉(zhuǎn)載至 我的博客
創(chuàng)建 Hexo 項(xiàng)目
安裝 Hexo 依賴
首先你需要安裝以下應(yīng)用程序官方教程:
在 Mac 上安裝軟件,通常使用 Homebrew,安裝命令如下:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝 Hexo
使用 npm 安裝 Hexo
npm install -g hexo-cli
然后執(zhí)行如下代碼查看 Hexo 版本
hexo -v
創(chuàng)建 Hexo 項(xiàng)目
首先創(chuàng)建一個(gè) Hexo 項(xiàng)目
hexo init <folder>
cd <folder>
npm install
關(guān)于 Hexo 的使用大家可以查看官方文檔
配置 VPS
我這里使用的是阿里云服務(wù)器,使用 root 用戶登錄。
Nginx
安裝 Nginx
apt-get update
apt-get install nginx
配置 Nginx
/root/blog
用于存放網(wǎng)站的靜態(tài)文件
mkdir /root/blog
創(chuàng)建 blog 的 Nginx 配置
vi /etc/nginx/conf.d/blog.conf
配置 80 端口及博客路徑
server {
listen 80;
root /root/blog;
}
如果后續(xù)發(fā)現(xiàn)部署完畢后通過 80 端口訪問一直顯示 Nginx 歡迎頁面, 通過設(shè)置
/etc/nginx/sites-enables/
中default
的配置而钞,把默認(rèn)的 Nginx 歡迎頁面調(diào)整到其他端口就行了
重啟 Nginx
sudo service nginx restart
Git Hooks
安裝 Git
apt-get install git-core
創(chuàng)建 Git 庫(kù)
創(chuàng)建一個(gè) git 的倉(cāng)庫(kù),博客靜態(tài)文件將通過 Hexo 部署 push
到此 git 庫(kù)當(dāng)中
mkdir /root/blog.git
cd /root/blog.git
git init --bare
Hooks 監(jiān)聽代碼提交
vim /root/blog.git/hooks/post-receive
# 打開可執(zhí)行權(quán)限
chmod +x /root/blog.git/hooks/post-receive
腳本僅僅把 /root/blog
替換為 git
庫(kù)中的內(nèi)容
#!/bin/bash
rm -rf /root/blog
git clone /root/blog.git /root/blog
部署及更新 blog
配置 _config.yml
文件
.
.
.
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: 'git'
repo: root@80.23.43.19:blog.git
部署
hexo deploy
等待部署完畢,輸入的你的 ip 地址或域名就能看見 Hexo 為你生成的靜態(tài)博客了熄诡。