「Hexo」 搭建部署
Hexo 安装
-
安装Node.js
-
安装Git
-
安装Hexo
1sudo npm install -g hexo-cli
如果在mac中安装报
/usr/lib/node_modules/
的操作权限问题,执行以下命令。1sudo chown -R `whoami` /usr/local/lib/node_modules
-
初始化项目
1hexo init blog
创建完成后,当前目录下会有一个
xx_blog
的文件夹,具体的文件夹查询官网hexo.io
Hexo 部署到Nginx & Github.io
开发机
在自己写Blog的Pc上安装插件
1yarn add hexo-deployer-git
服务器
-
在即将部署的服务器上执行以下操作
1yum install git 2 3useradd -m git # 创建一个git用户,用来运行git服务 4 # 新建git用户并非必要,但是为了安全起见,还是用git用户单独来运行git服务 5 6passwd git
-
设置PC到服务器的git用户免密登录
1# 生成ssh密钥 2ssh-keygen 3# 将公钥添加到server 4ssh-copy-id git@serverIp
-
在服务器上初始化一个Git仓库
1mkdir -p /var/repo 2ca /var/repo 3git init --bare blog.git # --bare 初始化一个裸仓库,裸仓库没有工作区,只为共享而存在 4chown -R git:git blog.git
配置Git hooks
1mkdir /var/repo/blog.git/hooks 2vi post-receive
写入以下内容
1#!/bin/sh 2git --work-tree=/var/www/blog --git-dir=/home/git/byte_gopher_blog.git checkout -f 3# /var/www/blog 是部署目录。 每次push完成之后
增加可执行权限
1chmod +x /var/repo/blog.git/hooks/post-receive
禁用git用户的shell登录权限
1vi /etc/passwd 2# git❌1001:1001:,,,:/home/git:/bin/bash 3 git❌1001:1001:,,,:/home/git:/usr/bin/git-shell
最后再禁用
-
部署nginx
创建需要的代理文件夹
1mkdir -p /home/www/hexo #创建目录 2chown -R git:git /home/www/hexo # 增加git用户权限
修改nginx配置
/etc/nginx/nginx.conf
1 server { 2 listen 80 default_server; 3 listen [::]:80 default_server; 4 server_name _; 5 root /home/www/hexo; 6 7 include /etc/nginx/default.d/*.conf; 8 9 location / { 10 } 11 12 error_page 404 /404.html; 13 location = /40x.html { 14 } 15 16 error_page 500 502 503 504 /50x.html; 17 location = /50x.html { 18 } 19 }
-
配置hexo
_config.yml
1# URL 2## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' 3url: https://www.bytegopher.com # 为了避免不必要的麻烦此处设置根域名 & 根目录 4root: / 5 6# Deployment
branch: gh-pages # branch name, whaterver
-
-
发布Blog
写完博客之后直接发布就可以更新到Nginx服务器& Github.io
1hexo clean & hexo d -g
?
Config
md conf
1title: Hello Hexo! 2layout: post 3subtitle: "hello word, welcome" 4date: 2020-07-26 01:09:53 5author: "Airren" 6catalog: true 7header-img: "post-bg-js-module.jpg" 8tags: 9 - Life
_config.yml
1# Hexo Configuration 2## Docs: https://hexo.io/docs/configuration.html 3## Source: https://github.com/hexojs/hexo/ 4 5# Site 6title: ByteGopher 7subtitle: To Be A Lean Developer! 8author: Airren 9language: en 10timezone: Asia/Shanghai 11 12# URL 13## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' 14url: https://www.bytegopher.com 15root: / 16permalink: :year/:month/:day/:title/ 17permalink_defaults: 18 19#Custom Setting Start 20 21# Site settings 22SEOTitle: ByteGopher | Airren 23header-img: img/home-bg.jpg 24email: renqiqiang@outlook.com 25description: "ByteGopher" 26keyword: "ByteGopher, Airren" 27 28 29# SNS settings 30# RSS: false 31# weibo_username: Demonbane 32# zhihu_username: Demonbane 33github_username: Airren 34twitter_username: Airrenz 35facebook_username: Airrenz 36linkedin_username: 强-任-b8a3b4103 37 38# Build settings 39anchorjs: true # if you want to customize anchor. check out line:181 of `post.html` 40 41 42# Disqus settings 43disqus_username: bytegopher 44 45# Duoshuo settings 46# duoshuo_username: kaijun 47# Share component is depend on Comment so we can NOT use share only. 48# duoshuo_share: true # set to false if you want to use Comment without Sharing 49 50 51# Analytics settings 52# Baidu Analytics 53ba_track_id: 4cc1f2d8f3067386cc5cdb626a202900 54# Google Analytics 55ga_track_id: 'UA-49627206-1' # Format: UA-xxxxxx-xx 56ga_domain: bytegopher.com 57 58 59# Sidebar settings 60sidebar: true # whether or not using Sidebar. 61sidebar-about-description: "Hi, welcome!" 62sidebar-avatar: ./img/avatar.jpg # use absolute URL, seeing it's used in both `/` and `/about/` 63 64 65# Featured Tags 66featured-tags: true # whether or not using Feature-Tags 67featured-condition-size: 1 # A tag will be featured if the size of it is more than this condition value 68 69 70# Friends 71friends: [ 72 { 73 title: "Kaijun's Blog", 74 href: "http://blog.kaijun.rocks" 75 },{ 76 title: "Hux Blog", 77 href: "http://huangxuan.me" 78 }, 79] 80 81 82#Custom Setting End 83 84 85 86# Directory 87source_dir: source 88public_dir: public 89tag_dir: tags 90archive_dir: i_dont_wanna_use_default_archives 91category_dir: categories 92code_dir: downloads/code 93i18n_dir: :lang 94skip_render: 95 96# Writing 97new_post_name: :title.md # File name of new posts 98default_layout: post 99titlecase: false # Transform title into titlecase 100external_link: true # Open external links in new tab 101filename_case: 0 102render_drafts: false 103post_asset_folder: true 104relative_link: false 105future: true 106highlight: 107 enable: true 108 line_number: true 109 auto_detect: true 110 tab_replace: 111 112# Category & Tag 113default_category: uncategorized 114category_map: 115tag_map: 116 117# Date / Time format 118## Hexo uses Moment.js to parse and display date 119## You can customize the date format as defined in 120## http://momentjs.com/docs/#/displaying/format/ 121date_format: YYYY-MM-DD 122time_format: HH:mm:ss 123 124# Pagination 125## Set per_page to 0 to disable pagination 126per_page: 10 127pagination_dir: page 128 129# Extensions 130## Plugins: https://hexo.io/plugins/ 131## Themes: https://hexo.io/themes/ 132theme: huxblog 133 134# Deployment 135## Docs: https://hexo.io/docs/deployment.html 136deploy: 137 type: git 138 repo: 139 github: https://github.com/Airren/airren.github.io 140 alios: git@hongkong:/home/git/blog.git 141 branch: gh-pages 142 143index_generator: 144 per_page: 3 ##首頁默认10篇文章标题 如果值为0不分页 145archive_generator: 146 per_page: 10 ##归档页面默认10篇文章标题 147 yearly: true ##生成年视图 148 monthly: true ##生成月视图 149tag_generator: 150 per_page: 10 ##标签分类页面默认10篇文章 151category_generator: 152 per_page: 10 ###分类页面默认10篇文章
Hexo Write
Page
1hexo new page --path about/me "About me"
1INFO Created: ~/Desktop/ByteGopher/airren_blog/source/about/me.md
Post
1hexo new post -p web/https_tips "HTTPS Tips"
1INFO Created: ~/Desktop/ByteGopher/airren_blog/source/_posts/web/https_tips.md
reference:
https://xdlrt.github.io/2016/02/18/2016-02-18/ https://www.lagou.com/lgeduarticle/40391.html https://juejin.im/post/5ab47e48f265da23805991dc https://blog.csdn.net/weixin_42646103/article/details/105181586?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param https://zhuanlan.zhihu.com/p/158678677 https://oakland.github.io/2016/05/02/hexo-%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%90%E4%B8%80%E7%AF%87%E6%96%B0%E7%9A%84post/ https://www.jianshu.com/p/e20deec143b1
参考资料
https://www.jianshu.com/p/e1ccd49b4e5d