AO3 镜像站搭建全攻略

前言

AO3(Archive of Our Own)是全球最大的同人作品存档网站,但由于众所周知的原因,国内直接访问经常出现加载失败、图片裂开、甚至 525 错误。搭建一个 AO3 镜像站,可以让访问更稳定。

本文将从零开始,详细讲解如何搭建一套高可用、自动化、可监控的 AO3 镜像站系统。

架构概览

整个系统由三部分组成:

  • Cloudflare Worker:反代入口,负责请求转发和节点分配
  • Vercel 节点:8 个独立部署的反代节点,分散负载
  • 健康监控:自动检测各节点状态,故障时自动切换

前期准备

平台 用途 费用
Cloudflare Worker 部署 + DNS 免费
GitHub 源码托管 + CI/CD 免费
Vercel 部署 8 个反代节点 免费

第一步:部署 Cloudflare Worker

核心代码(关键部分已脱敏):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const AO3_TARGET = 'https://archiveofourown.org';
const VERCELL_NODES = [
'https://node-1.your-app.vercel.app',
// ... 8 个节点
];

export default {
async fetch(request) {
const url = new URL(request.url);
const targetUrl = AO3_TARGET + url.pathname + url.search;
return fetch(targetUrl, {
headers: { 'Host': 'archiveofourown.org' }
});
}
};

第二步:部署 Vercel 节点

同一个代码库,创建 8 个 Vercel 项目:

1
2
3
for i in $(seq 1 8); do
vercel deploy --prod --name "ao3-node-$i"
done

第三步:智能负载均衡

1
2
3
4
5
6
7
8
9
10
11
async function getBestNode() {
let best = null, bestLatency = Infinity;
for (const node of VERCELL_NODES) {
const health = await checkNodeHealth(node);
if (health.ok && health.latency < bestLatency) {
bestLatency = health.latency;
best = node;
}
}
return best || VERCELL_NODES[0];
}

常见问题

  1. 图片加载失败:在 Worker 中劫持图片请求单独转发
  2. 525 错误:检查 SSL/TLS 设置为 Full(严格模式)
  3. 页面空白:确保 Worker 正确替换了资源链接中的域名

总结

通过以上步骤,就能搭建一套完整的 AO3 镜像站系统,全免费且可灵活扩展。

免责声明:本文仅用于技术学习和交流。请遵守当地法律法规。