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便可。

相關文章
相關標籤/搜索