0.前言

假定目前已经知道如果创建hexo博客并部署到Github Pages中,所以客户端已安装了hexo并且有了hexo博客项目。

1.服务端配置

1.1 创建博客文件目录

该目录用于存放生成的hexo最终页面文件。

mkdir -p /data/www/hexo

1.2 创建Git项目

cd /root/Data
git init --bare hexo.git

1.3 创建Git钩子(hook)

编辑/root/Data/hexo.git/hooks/post-receive文件,内容如下:

#!/bin/bash
git --work-tree=/data/www/hexo --git-dir=/root/Data/hexo.git checkout -f

同时给该文件添加可执行权限:

chmod +x /root/Data/hexo.git/hooks/post-receive

1.4 配置nginx

nginx配置文件/etc/nginx/nginx.conf内容大致如:

server {
    listen       80;
    server_name  www.lightsmile.cn;

    #把http的域名请求转成https
    return 301 https://$host$request_uri;
}

# Settings for a TLS enabled server.
server {
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl http2 default_server;
    server_name  www.lightsmile.cn;
    root         /data/www/hexo;
    index index.html index.htm;

    ssl_certificate 1_www.lightsmile.cn_bundle.crt;
    ssl_certificate_key 2_www.lightsmile.cn.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:1m;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location /blog {
        alias  /data/www/hexo;
        index index.html index.htm;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

配置完后使用nginx -t命令检查nginx配置是否正确,之后使用systemctl restart nginx重启nginx以使配置生效。

2.客户端配置

2.1 安装hexo插件

npm install hexo-server hexo-deployer-git -g

2.2 修改hexo项目配置文件_config.yml

其中主要的配置包含:

url: https://www.lightsmile.cn/blog
root: /blog/
deploy:
  type: git
  repo: tencent_cloud2:/root/Data/hexo
  branch: master

其中url指定博客网址路由,root指定次级路由,而deploy则指定部署配置信息,其中的repo格式为:服务器主机名:项目地址,我这里是tencent_cloud2是因为我通过ssh的config配置了远程服务器的免密登录,路径为C:\Users\Alienware\.ssh\config,内容大致如下:

# 新腾讯云服务器
Host tencent_cloud2
    HostName 49.232.27.108
    User root
    Port 22
    IdentityFile ~/.ssh/tencent_cloud2

2.3 重新生成项目

hexo clean # 清空项目
hexo generate -d # 重新生成文件并部署到服务器中

之后可以输入网址,或者查看服务器下的/data/www/hexo目录已查看是否包含博客网页源码以查看是否博客更新部署成功~

参考

  1. Hexo 个人博客部署到 CentOS 个人服务器 - SegmentFault 思否
  2. SSL 证书 Nginx 服务器 SSL 证书安装部署 - 证书安装 - 文档中心 - 腾讯云
  3. 配置VSCode-Remote-SSH - lightsmile’s Blog

评论




博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议

本站使用 Volantis 作为主题,总访问量为
载入天数...载入时分秒...
冀ICP备20001334号