从零开始快速搭建hexo(ubuntu)

从零开始快速搭建hexo(ubuntu)

一月 24, 2019

为了好记我现在就把坑给填了

更新源:(因为版本不一样,根据自己的版本百度就行)。

安装nginx

1
2
$sudo apt-get update
$sudo apt-get install nginx -y

安装git

1
$sudo apt-get install git

安装nodejs

1
$sudo apt-get install nodejs 

安装npm

1
$sudo apt-get install npm

hexo-cli和hexo-server 安装

1
$sudo npm install hexo-cli hexo-server -g

创建一个hexo文件夹把hexo部署到这里

1
2
3
$sudo mkdir hexo
$cd hexo
$hexo init

安装插件(非必要)

1
2
$sudo npm install hexo-generator-search --save
$sudo npm install hexo-generator-tag --save

生成自己的第一个md文本

1
$sudo hexo new "hello world"

进行部署成网页文件

1
$sudo hexo g

确认身份

1
$sudo git config --global user.email "邮箱"

昵称

1
$sudo git config --global user.name "名称"

在/var/目录下创建repo目录并赋予所有用户写的权限并且部署

1
2
3
$cd /var/ && mkdir repo
$sudo chmod 755 repo
$sudo cd repo/ && git init --bare hexo_static.git

配置Nginx托管

在/var/www/目录下创建hexo目录并赋予权限

1
2
$cd /var/www/
$sudo mkdir hexo && sudo chmod 755 hexo

编辑Nginx配置文件

1
2
$sudo vim /etc/nginx/sites-available/default //如果提示没有vim可以安装
$sudo apt install vim -y //安装vim

把网页指向从原来的html指向刚刚创建的hexo目录

1
$sudo vim /etc/nginx/sites-available/default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/hexo;//把这句的html改成hexo

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}



# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}


按esc 然后输入:wq

1
$sudo service nginx restart

配置git

1
$sudo vim /var/repo/hexo_static.git/hooks/post-receive

加入

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

:wq退出保存

赋予其可执行权限

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

配置本地hexo在自己刚刚创建hexo的目录下

1
$cd hexo
1
$sudo vim _config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: sanka//修改成自己的
subtitle:
description:
keywords:
author: sanka//修该为自己
language:
timezone:

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

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: draft //修改为草稿
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git //改为git
repo: 主机名@云服务器的IP地址:/var/repo/hexo_static //自己添加
branch: master //需要自己加

测试,在hexo目录下

1
$sudo npm install hexo-deployer-git --save //安装推送包
1
$sudo hexo generate && hexo deploy

就部署完成了