Hexo博客部署到我的服务器

本文跳过阿里云建立git仓库、hexo部署到github的步骤,有须要的能够移步下面博客地址查看:php

  1. 在阿里云服务器上建立git远程仓库css

  2. 使用Hexo创建博客html

1、服务器相关配置

<!--more-->git

本文使用hexo在本地生成静态文件,而后将静态文件提交到我的服务器的git仓库,最后用Nginx提供web服务的方式。github

一、Nginx配置

Nginx正常配置一个虚拟主机来存放静态文件便可。web

server
     {
         listen 80;
         #listen [::]:80;
         server_name sjzlai.qicunshan.com ;
         index index.html index.htm index.php default.html default.htm default.php;
         root  /home/wwwroot/blog.qicunshan.com/blog;

         #include other.conf;
         #error_page   404   /404.html;

         # Deny access to PHP files in specific directory
         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

         include enable-php.conf;

         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
         {
             expires      30d;
         }

         location ~ .*\.(js|css)?$
         {
             expires      12h;
         }

         location ~ /.well-known {
             allow all;
         }

         location ~ /\.
         {
             deny all;
         }

         access_log  /home/wwwlogs/blog.qicunshan.com.log;
     }

须要注意的是:vim

  • git用户的权限;bash

  • 虚拟主机路径,且默认主页是index.html。服务器

二、建立git仓库

#建立仓库目录
    mkdir blog.git
    #进入仓库目录
    cd blog.git
    #建立仓库
    git init --bare

建立完后能够使用下面命令测试一下仓库地址,克隆成功说明没有问题。hexo

git clone 仓库地址

三、Git hooks配置

  • 新建脚本,使git hooks每次push完成以后,将仓库中的静态文件复制到Nginx对应的虚拟主机中;
#新建脚本
 vim post-receive
脚本内容以下:
#!/bin/bash -l
#git仓库目录
GIT_REPO=/var/git/blog.git
#临时文件目录
TMP_GIT_CLONE=/var/git/tmp/blog
#虚拟主机目录
PUBLIC_WWW=/home/wwwroot/blog.qicunshan.com
rm -rf ${TMP_GIT_CLONE}
git clone $GIT_REPO $TMP_GIT_CLONE
rm -rf ${PUBLIC_WWW}/*
cp -rf ${TMP_GIT_CLONE} ${PUBLIC_WWW}
  • git用户关于post-receive脚本及内容的权限、虚拟主机的权限:
#赋予文件、文件夹权限
    chmod 777 post-receive
    chmod 777 -R /var/git/tmp
    chmod 777 -R /home/wwwroot/blog.qicunshan.com
    #赋予git用户权限
    chown git:git -R /var/git/tmp
    chown git:git -R /home/wwwroot/blog.qicunshan.com

2、本机Hexo配置

deploy:
      type: git
      #repo: git@github.com:qicunshan/qicunshan.github.io.git
      repo:
        github: git@github.com:qicunshan/qicunshan.github.io.git
        vps:  git@服务器地址:/home/hexo.git
      branch: master

而后在hexo目录下执行Hexo g -d便可。

相关文章
相关标签/搜索