前言✍️
在容器搭建的服务,容器部署后会给一个访问链接,运用CF Worker反向代理,使用自己的域名访问搭建的服务。
部署教程😎
创建Worker
反向代理代码
把所有github.com
修改为需要反向代理的域名
export default {
async fetch(request, env) {
const _url = new URL(request.url);
const hostname = _url.hostname
_url.hostname = "github.com"
const req = new Request(_url, request);
req.headers.set('origin', 'https://github.com');
const res = await fetch(req);
let newres = new Response(res.body, res);
let location = newres.headers.get('location');
if (location !== null && location !== "") {
location = location.replace('://github.com', '://'+hostname);
newres.headers.set('location', location);
}
return newres
},
};
绑定域名
优选加速
添加自定义域名使用路由格式,域名cname
cf的优选域名,路由区域选择域名,路由输入域名/*
即可完成优选加速
评论区