将博客部署到阿里云上

前言

通常,我们可以将博客部署到github,但是如果您觉得加载太慢,则可以选择将其部署到您自己的服务器上。

如果你还没有博客,要构建自己博客,请参阅 build blog

以阿里云服务器为例

  1. 首先购买阿里云服务器,请参考detail

  2. 登录到阿里云服务器 putty

  3. 使用超级用户登录后,创建普通用户。

     adduser xxxx
    
  4. 将普通用户添加到sudo组

     chmod 640 /etc/sudoers
     vim /etc/sudoers
    

    将以下语句添加到 /etc/sudoers

     xxxx    ALL=(ALL:ALL) ALL
    
  5. 如果发生此错误,请以普通用户身份登录: error: sudo: unable to resolve xxxx

    步骤 1:

     vim /etc/hostname
    

    将以下语句添加到 /etc/hostname

     xxxx
    

    步骤 2:

     vim /etc/hosts
    

    将以下语句添加到 to /etc/hosts

     127.0.0.1       localhost xxxx
    

    接下来:

     sudo apt-get install git
    

    error: Unable to locate package git

    解决方法:

     sudo apt-get update
    
  6. 再增加一个git用户

     adduser git
     su git
     cd /home/git/
     mkdir -p sources/blog
     mkdir repos && cd repos
     git init --bare blog.git
     cd blog.git/hooks
    

    将以下语句添加到 blog.git/hooks

     git --work-tree=/home/git/sources/blog --git-dir=/home/git/repos/blog.git checkout -f
    

    接下来:

     chmod +x post-receive
    
  7. 测试git仓库

    PC客户端也就是:

     ssh-keygen
     vim id_rsa.pub
    

    复制里面的内容

    阿里云服务器:

     sudo vim  /home/git/.ssh/authorized_keys
    

    粘贴上个步骤复制的内容

     git clone git@server_ip:/home/git/repos/blog.git
    
  8. 创建一个nginx服务器

     cd /usr/local/src
     wget http://nginx.org/download/nginx-1.15.2.tar.gz
     tar xzvf nginx-1.15.2.tar.gz
     cd nginx-1.15.2
     ./configure
     make && make install
     alias nginx='/usr/local/nginx/sbin/nginx'
    
  9. 编辑这个文件/usr/local/nginx/conf/nginx.conf

    hexoOnServer

  10. 开机自启nginx

    sudo vim /etc/init.d/nginx.sh
    

    将以下语句添加到 t/etc/init.d/nginx.sh

	#auto run nginx when system startup
	sudo -S /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf << EOF
	password
	EOF
	exit 0
sudo update-rc.d  nginx.sh defaults

11. 配置文件 _config.yml

hexoOnServer


12. 将博客部署到服务器
	hexo clean && hexo g -d

13. 您必须在阿里云上添加安全组,否则端口80不可用

hexoOnServer

转载请注明出处:http://www.wolfnx.com/2018/03/16/HexoDeployOnAliyun

作者 : wolfnx
邮箱 : wolfnx@outlook.com
邮箱2 : lostnx@gmail.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值