阿里云服务器搭建hexoblog

使用阿里云服务器搭建hexoblog

创建服务器坑

购买阿里云轻量级服务器,观看了各种镜像说明最终选择了镜像系统BT-Panel(宝塔Linux面板是一款使用方便、功能强大的服务器管理软件。面板集成一键配置:LAMP/LNMP/Tomcat/Node.js、网站、数据库、FTP、SSL,可以通过Web端轻松管理服务器。该镜像基于CentOS 7.3 64位操作系统。),根据教程设置并登录了宝塔系统,之后新建网站,网站名为/www/wwwroot.

BT-Panel提供了ftp服务, 然而hexo有sftp,ftpsync,git 等推送方式,就是没有ftp方式,所以我就想能否用git仓库来搭建.

期初想着把git仓库直接放在网站目录下,这样就可以直接将发布的笔记推送到服务器.于是在/www/wwwroot/robocup3d 目录下使用 git init robocup3d建立git仓库, 在推送的时候却出现了问题,

  • git init 建立仓库会在目录下生成work-tree
  • git --bare init 建立的仓库没有work-tree
remote: error: is denied, because it will make the index and work tree inconsis
ent
remote: error: with what you pushed, and will require 'git reset --hard' to mat
h
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int

remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in som

remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://root@192.168.1.8:/var/www/drupal/web
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://root@192.168.1.8:/var/www/drupal/web'

经过研究发现是因为git仓库拒绝推送,根据提示使在服务器的仓库中用命令git config receive.denyCurrentBranch = ignore ,设置完成后尝试推送,成功,大喜! 然而测试更新文章时却发现推送成功,网站却没有更新,
再研究…

最终发现, 我使用git init 来初始化仓库时,虽然会自动在项目文件夹中生成work-tree ,然后,有新的版本推送过来后,work-tree的内容不会自动更新,需要在代码仓库中使用git reset --hard来跟新 WTF? 难道我每次推送完了还是要去服务器上手动更新?

这个问题应该有办法解决吧? 经过研究…

最终发现了git的hooks功能,该功能相当于一个回调函数,当有新版本被推送到达时触发执行. 于是我删除了原本的代码仓库, 在服务器的root目录下建立了代码仓库git --bare init robocup3Book 代码仓库,

然后在仓库中的hooks文件夹中创建文件,post-receive文件,并写入内容:

[root@localhost]$ cd /home/workspace/wwwroot.git/hooks
[root@localhost]$ cat > post-receive <<EOF
>#!/bin/bash
>git --work-tree=/www/wwwroot/robocup3d checkout -f 
>EOF
[root@localhost]$ chmod +x post-receive

之后在hexo中执行hexo d 将web推送到仓库的master分支, git的hooks功能将会自动把work-tree加载到服务器文件夹下:/www/wwwroot/robocup3d

hexo命令坑

执行hexo new fileName , 该命令会默认在_posts文件夹下新建一个笔记, 如果笔记太多岂不是非常乱?

研究发现,在_posts文件夹下要生成子文件夹需要使用hexo new -p dirname/fileName fileName , fileName需要写两次…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值