Hexo博客搭建

進過上一篇《樹莓派搭建私人服務器》,咱們已經有一個私人服務器了,如今須要作點什麼實際事情了,先搭一個博客分享本身的經驗吧。javascript

原文地址:http://www.uthinks.com/wordpress/2017/12/31/%E5%9F%BA%E4%BA%8Ehexo-git-nginx%E7%9A%84%E5%8D%9A%E5%AE%A2%E5%8F%91%E5%B8%83/
相關文章:
1.《樹莓派搭建私人服務器》
(http://www.uthinks.com/wordpress/2017/12/30/raspberrypi-init/)css

準備工做

  1. 環境已經初始化的樹莓派
  2. Git服務器,我用的是本身搭建的Git服務器,固然也能夠使用GitHud
  3. Nginx
  4. Hexo,我朋友已經寫過關於Hexo詳細的文檔,這裏就不在贅述。
    (http://luckykun.com/work/2016-04-23/heoll-hexo.html)

Git服務器搭建

  1. 首先在樹莓派上安裝Git,同時確保ssh已經正確安裝而且默認開啓html

    sudo apt-get install wget git-core
  2. 添加git用戶和組,其實就是Linux普通用戶就行java

    adduser git
     passwd git
  3. 切換到git用戶,增長一個新的Git倉庫node

    cd /home/git
     mkdir blog
     cd blog
     git init --bare
  4. 本地把blog項目遷移下來, 剛剛初始化的倉庫是沒有任何分支的,後面提交代碼的時候會自動生成一個master分支。後面hexo直接在該目錄下搭建python

    git clone git@[域名 | IP]:/home/git/blog
  5. 至此,一個本身的git服務器已經搭建完成nginx

附錄

  1. 初始化空Git倉庫git init 和 git init --bare有什麼區別
    (http://blog.csdn.net/feizxiang3/article/details/8065506)

Nginx安裝配置

  1. 首先安裝nginxgit

    sudo apt-get install nginx
  2. 修改nginx配置文件 /etc/nginx/nginx.confjson

    user www-data;
     worker_processes 4;
     pid /run/nginx.pid;
    
     events {
         worker_connections 768;
         # multi_accept on;
     }
    
     http {
             server {
                     listen  8081;
                     # 這個目錄是hexo生成的頁面路徑,後面提交到git的頁面同步到這個目錄下
                     location / {
                             root   /home/bill/blog/public;
                             index  index.html;
                     }
    
                     # 這個配置是靜態文件:圖片、文件下載路徑,有另一個git倉庫管理,同樣同步到對應目錄下
                     location ~ ^/resource/picture/(.*)? {
                         alias /home/bill/resource/picture/$1 ;
                         add_header Cache-control max-age=7200,s-maxage=3600;
                     }
             }
    
             ##
             # Basic Settings
             ##
    
             sendfile on;
             tcp_nopush on;
             tcp_nodelay on;
             keepalive_timeout 65;
             types_hash_max_size 2048;
             # server_tokens off;
    
             # server_names_hash_bucket_size 64;
             # server_name_in_redirect off;
    
             include /etc/nginx/mime.types;
             default_type application/octet-stream;
    
             ##
             # SSL Settings
             ##
    
             ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
             ssl_prefer_server_ciphers on;
    
             ##
             # Logging Settings
             ##
    
             access_log /var/log/nginx/access.log;
             error_log /var/log/nginx/error.log;
    
             ##
             # Gzip Settings
             ##
    
             gzip on;
             gzip_disable "msie6";
    
             # gzip_vary on;
             # gzip_proxied any;
             # gzip_comp_level 6;
             # gzip_buffers 16 8k;
             # gzip_http_version 1.1;
             # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
             ##
             # Virtual Host Configs
             ##
    
             include /etc/nginx/conf.d/*.conf;
             include /etc/nginx/sites-enabled/*;
     }
  3. 啓動nginx服務器

    sudo /etc/init.d/nginx start | restart | stop

博客的發佈

環境已經搭建完成了,如何實現把文件提交到Git自動同步到nginx目錄下完成發佈呢?

1.若是你使用的GitHud的話這個問題很簡單,這裏就不在贅述。參考我朋友的hexo教程
(http://luckykun.com/work/2016-04-23/heoll-hexo.html)

2.如今說說個人方法,其實也很簡單

  • 編寫一個簡單的git pull腳本

    import os
    
      if __name__ == '__main__':
          #blog分支同步
          os.chdir('/home/bill/blog/')
          os.system('git pull origin master')
    
          #靜態文件同步
          os.chdir('/home/bill/resource/')
          os.system('git pull origin master')
  • 定時任務配置 crontab -e

    */1 * * * * /usr/bin/python /home/bill/deploy/deploy.py

若是個人文章對你有幫助,或者有什麼疑問。歡迎在下方留言,一塊兒交流討論

相關文章
相關標籤/搜索