Face the fear, create the future.

Face the fear, create the future.

直面恐惧,创造未来。

探究摄影、写作和技术。欢迎访问Petalzu的个人网站。

关于本站主题:Icarus

关于本站框架:Hexo

在GitHub Pages 上部署 Icarus

本地部署

在本地建立hexo文件夹,安装以下应用程序:

Node.js (Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本)
Git

执行如下命令:

1
npm install hexo

添加Hexo 所在的目录下的 node_modules 添加到环境变量之中

在想要建立hexo的 下执行如下命令:

1
2
3
hexo init <folder>
cd <folder>
npm install

在 Hexo 根目录执行以下命令安装主题,有两种方式:

1
npm npm install -S hexo-theme-icarus hexo-renderer-inferno

在 Hexo 根目录的 _config.yml 文件中,将 theme 值修改为 Icarus:

1
theme: icarus

或执行命令:

1
hexo config theme icarus

添加新页:

1
hexo new page

启动hexo服务器,访问 localhost:4000 查看效果:

1
hexo server

推送

建立存储库,名为 <你的 GitHub 用户名>.github.io

将 main 分支 push 到 GitHub仓库:

1
git push -u origin main

或者使用GitHub Desktop等工具进行推送。

使用 node –version 指令检查你电脑上的 Node.js 版本,并记下该版本 (例如:v18.16.0)
在储存库中前往 Settings > Pages > Source,并将 Source 改为 GitHub Actions。
在储存库中建立 .github/workflows/pages.yml,并填入以下内容:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Pages

on:
push:
branches:
- master # default branch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
# Examples: 20, 18.19, >=16.20.2, lts/Iron, lts/Hydrogen, *, latest, current, node
# Ref: https://github.com/actions/setup-node#supported-version-syntax
node-version: "20"
- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

检查 https://<你的 GitHub 用户名>.github.io 是否已经部署成功。

RSS

在 Hexo 根目录执行以下命令安装插件:

1
npm install hexo-generator-feed --save

在 Hexo 根目录的 _config.yml 文件中,添加以下内容:

1
2
3
4
5
6
feed:
type: rss2
path: sitemap.xml
limit: 20
hub:
content: false

在 _config.icarus.yml 文件中,找到RSS配置并修改为以下形式:

1
2
3
RSS:
icon: fas fa-rss
url: /sitemap.xml

推送

建立存储库,名为 <你的 GitHub 用户名>.github.io

将 main 分支 push 到 GitHub仓库:

1
$ git push -u origin main

或者使用GitHub Desktop等工具进行推送。

使用 node –version 指令检查你电脑上的 Node.js 版本,并记下该版本 (例如:v18.16.0)
在储存库中前往 Settings > Pages > Source,并将 Source 改为 GitHub Actions。
在储存库中建立 .github/workflows/pages.yml,并填入以下内容 (将 18.16.0 替换为上个步骤中记下的版本):

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#注:hexo官网上的wf文件配置出现了问题,因此我手动修改了一部分,以下是我自己使用的文件
name: Pages

on:
push:
branches:
- master # default branch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 18.16.0
uses: actions/setup-node@v3
with:
node-version: '18.16.0'
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./public
deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2

添加 CNAME 文件 在/source文件夹下,内容为你的域名,例如:

1
petalzu.top #替换为你的域名

检查 https://<你的 GitHub 用户名>.github.io 或 https://<你的域名> 是否已经部署成功。

Cloudflare CDN 加速访问和保护网站

需要域名

Cloudflare 解析

将域名导入cloudflare,设置DNS解析,并在域名供应商处修改DNS服务器为cloudflare提供的DNS服务器。

配置 DNSSEC,勾选其他cloudflare提供的安全选项。

Cloudflare WAF 配置

严格配置

创建如下规则,并对表达式或选项进行如下配置:

配置
 

放行爬虫

1
(cf.client.bot) or (cf.verified_bot_category eq "Search Engine Crawler") or (cf.verified_bot_category eq "Monitoring & Analytics") or (cf.verified_bot_category eq "Page Preview") or (cf.verified_bot_category eq "Advertising & Marketing")

选择操作:跳过 所有其余自定义规则

 
质询

1
(http.host eq "你的域名") or (http.host eq "你的子域名")

选择操作:交互式质询

较为宽松的配置

严格配置会带来很多问题,最明显的就是访问网站的速度变慢,需要用户操作,所以可以使用更加用户友好的托管质询。
托管质询可以自动判断是使用JS质询还是交互式质询,这几种质询方式的区别可以参照Cloudflare五秒盾、JS质询、托管质询以及交互式质询的区别
为了进一步防止隐患,可以规定更多的规则。

(实际上,JS质询也会占用不小的时间)

WAF规则

 
质询

1
(http.host eq "你的域名") or (http.host eq "你的子域名")

选择操作:托管质询

 
防恶意爬虫

1
(not cf.client.bot and not ip.geoip.country in {"CN" "HK" "JP" "MO" "SG" "TW" "US"}) or (cf.threat_score ge 5) or (not http.user_agent contains "Mozilla/") or (not http.request.version in {"HTTP/2" "HTTP/3" "SPDY/3.1"})

选择操作:阻止

 
阻止页面内容爬取

1
(http.request.uri.path contains ".php")

选择操作:阻止

速率限制规则

 
速率限制

1
(http.request.uri.path contains "/")

当速率超过 10010秒钟

选择操作:阻止 - 默认 Cloudflare 速率相应限制

HTTP DDoS 攻击防护

 
替代名称:ddos

规则操作集:阻止

规则集敏感度:高

其他

问题

  • 在hexo server中显示标签/分类/文章数目混乱,以及出现已删除的页面的情况,关闭server并使用如下命令:
1
$ hexo clean
  • 如果启用了 all_minifier: true,可能会遇到以下问题:
1
2
3
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: write EOF
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)

暂时只能通过关闭图像压缩解决:

1
all_minifier: false
  • 如果 excerpt 为空,会出现以下报错
1
2
ERROR Process failed:
ValidationError: `null` is not a string!

建议

除有必要,否则不推荐一键部署

参考文档

在 GitHub Pages 上部署 Hexo
配置CloudFlare WAF强制交互式质询让你的网站稳如泰山
简单操作让你的网站不受恶意流量恶意爬虫威胁!Cloudflare防火墙部署指南
Cloudflare五秒盾、JS质询、托管质询以及交互式质询的区别
Getting Started with Icarus

Face the fear, create the future.

https://petalzu.top/2024/01/18/page/

作者

Petalzu

发布于

2024-01-19

更新于

2024-07-24

许可协议

评论