简体中文 / [English]


Deploying Hexo to OSS for Faster Access in China

This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to the original Chinese version. I am continuously working to improve the translation.

My blog originally used Netlify with Alibaba Cloud CDN for acceleration within China.

But guess what… the origin server on Netlify turned out to be painfully slow. So slow that even a simple 304 response would often result in a 504 Gateway Timeout.

Since I’ve already gone through the备案 (ICP filing) process, I figured it’s time to make the site actually usable for domestic users.

So I decided to use GitHub Actions to deploy the site to Alibaba Cloud OSS, and then accelerate it via CDN.

Additionally, since comment posting in China requires moderation, I replaced Gitalk with Valine (along with Valine-Admin) to support manual review.

Here’s the GitHub Actions configuration file for reference. You’ll also need to set up the corresponding Secrets.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
name: Hexo Blog CI

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository master branch
uses: actions/checkout@master

- name: Setup Node.js 13.x
uses: actions/setup-node@master
with:
node-version: '13.x'

- name: Setup Hexo Dependencies
run: |
npm install
npm install -g hexo-cli
hexo clean
hexo generate
- name: setup aliyun oss
uses: manyuanrong/setup-ossutil@master
with:
endpoint: oss-cn-shanghai.aliyuncs.com
access-key-id: ${{ secrets.KEY }}
access-key-secret: ${{ secrets.SECRET }}
- name: cp files to aliyun
run: ossutil cp -rf public oss://hexo-blog-cn/

Note: Don’t use Node.js 14.x here—otherwise the generated HTML files will be empty. At first I thought it was an OSS issue, but nope, it was the Node version.

The pay-as-you-go cost is practically negligible.

See this detailed tutorial for more information.

Also, here’s a guide on setting up Valine and Valine-Admin.

This article is licensed under the CC BY-NC-SA 4.0 license.

Author: lyc8503, Article link: https://blog.lyc8503.net/en/post/hexo-on-oss/
If this article was helpful or interesting to you, consider buy me a coffee¬_¬
Feel free to comment in English below o/