Transfer Github Pages with Jekyll to your host

Github pages is a convenient way to deploy static webpages, however, GitHub page CDN nodes are not convenient for clients from China mainland, and can’t deploy some analytic tools. So I transfer my jekyll blog to my own host on Aliyun and write this pipeline tutorial.

enviroment

My host is an Aliyun VPS with 1 core, 2G ram and 5M bandwidth. Ubuntu 16.04 LTS,ruby 2.6,gem 3.0.3

steps

First, clone your repo to local.

git clone https://github.com/yourname/reponame.github.io.git

Second, delete old “gemfile.lock” file.

cd reponame.github.io
rm Gemfile.lock

Third, install jekyll and bundler. Gem, the ruby package manager, is needed here.

gem install jekyll bundle

If you find an error here, check the ruby version. In my original system image, the newest ruby version in apt repositories is 2.3. I have to delete 2.3 and install 2.6 as shown below:

sudo add-apt-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get purge --auto-remove ruby
sudo apt-get install ruby2.6 ruby2.6-dev

Fourth, install github-pages gem package. It’s a long process.

gem install github-pages

Fifth, use bundle to excute jekyll build command to build html files, which would output to root_dir/_site/ by default.

bundle exec jekyll build

Sixth, deploy the webpages. you can use jekyll serve command directly deploy web to http://localhost:4000.

bundle exec jekyll serve

And I deployed it on Nginx, so I can use some features of Nginx.

Here is an Nginx config example

server
{
	listen 80;
    listen 443 ssl http2;
    server_name grayxu.cn www.grayxu.cn;
    index index.html;
    root /home/gray/workplace/grayxu.github.io/_site;
    
    #SSL-START
    ssl_certificate    ...;
    ssl_certificate_key    ...;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

    #SSL-END
    
    #ERROR-PAGE-START
    error_page 404 /404.html;
    error_page 502 /502.html;
    #ERROR-PAGE-END
    
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    }

    ...
    
    access_log  /www/wwwlogs/www.grayxu.cn.log;
    error_log  /www/wwwlogs/www.grayxu.cn.error.log;
}

Other infos about deployment like git hook, pls refer to official doc

Github metadata warning

The reason is no local Jekyll Github Token. Adding export JEKYLL_GITHUB_TOKEN='***' can fix this.

results

Test results from different areas in China: image.png

By the way, image host is also transferred to UCLOUD OSS](https://ucloud.cn/). I use PicUploader as Web front end to upload images, which supports a number of OSS services.

update 2020/03/07: because of the conflict of root domain resolution between CNAME and mail, my blog has been transferred to “https://www.grayxu.cn” with UCLOUD CDN. The old “https://grayxu.cn” would be rewritten permanently to www. UCLOUD CDN sucks.

Search

    Table of Contents