Cloudflare 可以托管一些JS程序并运行,也能够使用自己的域名进行解析,当然也可以使用他提供的workers.dev
的域名。(截止2023年8月16日,本文再次更新修补的时候,该域名在国内污染严重)
在Cloudflare 的 Dashboard 找到Workers
Cloudflare Workers可以免費託管一些Js程序,我們可以通過它來反向代理。
1.登入CloudFlare帳戶
進入 https://dash/cloudflare.com/login 來登入帳戶。
![](https://images.tkong.com.cn/uploads/2022/08/202208070659071659855547-20210825050631456-2868.webp?imageMogr2/format/webp/interlace/1/quality/100)
2.打開Workers
![](https://images.tkong.com.cn/uploads/2022/08/202208070659101659855550-20210825050944136-1024x610222-1.webp?imageMogr2/format/webp/interlace/1/quality/100)
3.新建一個Workers
![](https://images.tkong.com.cn/uploads/2022/08/202208070659161659855556-20210825061733947-1024x610528-1.webp?imageMogr2/format/webp/interlace/1/quality/100)
4.貼上Code並部署
![](https://images.tkong.com.cn/uploads/2022/08/202208070659301659855570-20210825062318719-1024x610952-1.webp?imageMogr2/format/webp/interlace/1/quality/100)
addEventListener(
"fetch",event => {
let url=new URL(event.request.url);
url.hostname="www.tkong.net";
let request=new Request(url,event.request);
event. respondWith(
fetch(request)
)
}
)
5.完成
![](https://tkong-attachment.s.ahdark.com/2021/08/20210825062752542-1024x610.png)
打開這個網頁,可以看到反向代理已經成功。
![](https://tkong-attachment.s.ahdark.com/2021/08/20210825062840139-1024x610.png)
6.如何綁定獨立域
首先你需要使Cloudflare託管您的區域檔文件(DNS),也就是將域名添加到Cloudflare。
![](https://tkong-attachment.s.ahdark.com/2021/08/20210825063428160-1024x610.png)
![](https://tkong-attachment.s.ahdark.com/2021/08/20210825063859802-1024x610.png)