使用CloudFlare搭建反向代理
使用CloudFlare搭建反向代理
+使用CloudFlare搭建反向代理
使用CloudFlare搭建反向代理
互联网大善人!
准备
-
- 一个CloudFlare账号,如果没有就去CloudFlare注册
+这不废话- 一个CloudFlare账号,如果没有就去CloudFlare注册
这不废话- 一个可以添加到CloudFlare的域名(可选),主要是CloudFlare的一些域名被墙,导致无法直接访问
创建并配置Workers
在 Cloudflare 的面板左侧点击 Workers 和 Pages 进入后点击创建按钮
@@ -174,10 +174,15 @@-
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
// 域名映射表
const domainMappings = {
"/steam-store": "https://store.steampowered.com",
"/steam-api": "https://api.steampowered.com"
};
const specialCases = {
"*": {
"Origin": "DELETE",
"Referer": "DELETE"
}
};
function handleSpecialCases(request) {
const rules = specialCases["*"];
for (const [key, value] of Object.entries(rules)) {
switch (value) {
case "KEEP":
break;
case "DELETE":
request.headers.delete(key);
break;
default:
request.headers.set(key, value);
break;
}
}
}
async function handleRequest(request) {
const url = new URL(request.url);
// 如果是访问根目录就返回一个HTML
if (url.pathname === "/") {
return new Response(`
<html>
<head>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f9f9f9;
}
h1 {
font-family: Arial, sans-serif;
color: #333;
text-align: center;
}
</style>
</head>
<body>
<h1>Why don't you play Genshin Impact?</h1>
</body>
</html>
`, {
headers: { "Content-Type": "text/html" }
});
}
const basePath = Object.keys(domainMappings).find(path => url.pathname.startsWith(path));
if (!basePath) {
return new Response("Path not found in domain mappings", { status: 404 });
}
const targetBase = domainMappings[basePath];
const targetPath = url.pathname.slice(basePath.length) + url.search + url.hash;
const targetUrl = new URL(targetPath, targetBase);
const modifiedRequest = new Request(targetUrl, {
headers: request.headers,
method: request.method,
body: request.body,
redirect: 'follow'
});
handleSpecialCases(modifiedRequest);
const response = await fetch(modifiedRequest);
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');
return modifiedResponse;
}可修改 域名映射表(domainMappings) 中的内容为自己想要的网站
++可修改 域名映射表(domainMappings) 中的内容为自己想要的网站
+-
1
2
3
4
5 // 域名映射表
const domainMappings = {
"/steam-store": "https://store.steampowered.com",
"/steam-api": "https://api.steampowered.com"
}其中,前面的部分是路由,也就如果
+
访问 https://你的域名/steam-store 反代的就是 https://store.steampowered.com
访问 https://你的域名/steam-api 反代的就是 https://api.steampowered.com
其他同理,你可以添加也可以减少
点击部署其中,前面的部分是路由,就是 https://你的域名/路由 也就如果
+访问 https://你的域名/steam-store 反代的就是 https://store.steampowered.com
+
访问 https://你的域名/steam-api 反代的就是 https://api.steampowered.com其他同理,你可以添加也可以减少
+点击部署
在下方出现以下提示就可以啦
访问 https://你的域名 出现下面界面就成功啦
当然,有概率你是会出现网页无法访问,这就是CloudFlare的部分域名被墙了……
diff --git a/2024/11/29/hello-world/index.html b/2024/11/29/hello-world/index.html index 7727492..65a6f51 100644 --- a/2024/11/29/hello-world/index.html +++ b/2024/11/29/hello-world/index.html @@ -156,7 +156,7 @@ } detectApple() })(window) -Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
+Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1 $ hexo new "My New Post"More info: Writing
diff --git a/about/index.html b/about/index.html new file mode 100644 index 0000000..552b170 --- /dev/null +++ b/about/index.html @@ -0,0 +1,194 @@ +喜欢 | MapleLeaf + + + + + + + + + + +喜欢
评论\ No newline at end of file diff --git a/archives/2024/11/index.html b/archives/2024/11/index.html index fb86e69..b9737a9 100644 --- a/archives/2024/11/index.html +++ b/archives/2024/11/index.html @@ -54,7 +54,7 @@ isHome: false, isHighlightShrink: false, isToc: false, - postUpdate: '2024-11-30 17:56:06' + postUpdate: '2024-11-30 22:04:09' } -数据库加载中十一月 2024
文章总览 - 2\ No newline at end of file +数据库加载中十一月 2024
文章总览 - 2\ No newline at end of file diff --git a/archives/2024/index.html b/archives/2024/index.html index 492d63d..e43cdb5 100644 --- a/archives/2024/index.html +++ b/archives/2024/index.html @@ -54,7 +54,7 @@ isHome: false, isHighlightShrink: false, isToc: false, - postUpdate: '2024-11-30 17:56:06' + postUpdate: '2024-11-30 22:04:09' } -数据库加载中2024
文章总览 - 2数据库加载中