博客搭建(part1)

参考站点: https://www.qcloud.com/community

Server端:

一台安装了 Ubuntu 14.04 的ubuntu server (我直接用root账号执行server端全部命令)

安装必要的软件包:

apt-get updateapt-get

install git nginx vim -y

创建私有 Git 仓库

mkdir /var/repo

cd /var/repo/

git init --bare hexo_static.git

创建并配置 Nginx 托管文件目录

mkdir -p /var/www/hexo

修改 Nginx 的 default 配置文件/etc/nginx/sites-available/default 找到如下片段,并修改root值为 /var/www/hexo

...
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/hexo; # 需要修改的部分
index index.html index.htm;
...

重启nginx服务

service nginx restart

创建 Git 钩子

接下来,在服务器上的裸仓库 hexo_static 创建一个钩子,在满足特定条件时将静态 HTML 文件传
送到 Web 服务器的目录下,即 /var/www/hexo。

在自动生成的 hooks 目录下创建一个新的钩子文件/var/repo/hexo_static.git/hooks/post-receive 并写入

#!/bin/bash
git --work-tree=/var/www/hexo --git-dir=/var/repo/hexo_static.git checkout -f

为该文件添加可执行权限

chmod +x /var/repo/hexo_static.git/hooks/post-receive

Mac端:

安装Node.js 和 npm 可直接前往 https://nodejs.org/en 下载

hexo-cli 是 Hexo 的命令行工具,可用于快速新建、发布、部署博客;hexo-server 是 Hexo 的内建服务器,可用于部署前的预览和测试。两个工具可通过以下命令进行安装:(-g 选项,表示全局安装。)

npm install hexo-cli -g
npm install hexo-server -g

之后,需要安装一个 Hexo 包,负责将博客所需的静态内容发送到设置好的 Git 仓库。 npm install hexo-deployer-git --save

接下来,为 Hexo 博客做一些基础配置,包括创建基础文件。

hexo init ~/hexo_blog

在国内环境下执行该命令,速度会有些慢。因为需要从 Hexo 在 Github 上的仓库克隆;仓库克隆成功后,会自动执行一系列 npm 命令,自安装依赖模块。这时,我们就已经有了一个写作、管理博客的环境。

修改 Hexo 部分默认配置

其中,_config.yml 为 Hexo 的主配置文件。我们首先修改博客的 URL 地址。找到如下片段并修改url值

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://server-ip # 没有绑定域名时填写服务器的实际 IP 地址。
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

找到如下部分修改default_layout为draft(草稿)

#Writing
new_post_name: :title.md # File name of new posts
default_layout: draft # 原来的值是 post
titlecase: false # Transform title into titlecase

找到如下部分,填写部署的type为git及相应repo地址

deploy:
    type: #填写git 表示使用git发布博客 
    repo: #填写root@your_server_ip:/var/repo/hexo_static
    branch: master

试写个博客

hexo new first-post

你会看到类似如下输出:

INFO  Created: ~/hexo_blog/source/_draft/first-post.md

建议使用markdown编辑first-post.md文件 软件下载地址 http://macdown.uranusjr.com

随便写点啥

发布博客

hexo publish first-post

成功后会有如下提示:

INFO  Published: ~/hexo_blog/source/_draft/first-post.md

(直接在 source/_post/下面创建md文件可以省去publish过程)

本地查看

hexo server

同步到server

hexo generate && hexo deploy

期间会要求输入root登录密码

成功后会有如下提示:

INFO  Deploy done: git

FINISH ~













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值