使用CloudFlare Pages进行反代

准备材料

  • Github/ GitLab账号
  • CloudFlare 账号

正式步骤(这里只演示Github,GitLab类似)

打开Github,新建一个私有仓库

然后点击创建

点击creating a new file按钮

文件名设置为_worker.js,然后复制以下代码,在第五行单引号里改成你想要反代的网站

注意,反代的网站不需要加https,http,需要遵守类似www.baidu.com的格式

export default {
  async fetch(request, env) {
    let url = new URL(request.url);
    if (url.pathname.startsWith('/')) {
      url.hostname = '反代地址'
      let new_request = new Request(url, request);
      return fetch(new_request);
    }
    return env.ASSETS.fetch(request);
  },
};

然后保存

转到CloudFlare的Pages页面,按照下图操作

 

输入项目名称,其他不动,点击“Save and deploy”

部署完成

 

检查效果

 

总结

可以作为一种备用方法存着

同时也注意只有十万次

猜你喜欢

转载自blog.csdn.net/m0_58606834/article/details/125534836