Cloudflare Pages反代loc.cc后如何才能网站加速与域名优化?

浏览器用户 → loc.ccluadns DNS) → CNAME → Cloudflare Pages (*.pages.dev)

Pages分配的IP,国内好多不通。 有大佬讲下吗,如何才能网站加速与域名优化?

附上我的Pages反代 自己配置_worker.js文件打包zip上传Pages部署

export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url);
    const originalHost = request.headers.get("host");

    // 将 "ne.zha.x10.mx" 替换为您的目标服务地址
    const targetHost = "ne.zha.x10.mx"; 
    url.hostname = targetHost;

    // 如果目标服务使用 HTTPS,确保 protocol 是 https:
    url.protocol = "https:";

    // 保留原始请求方法、headers 和 body
    const newRequest = new Request(url.toString(), {
      method: request.method,
      headers: request.headers,
      body: request.body,
      redirect: "follow"
    });

    return fetch(newRequest);
  }
};
1 个赞

(帖子已被作者删除)

1 个赞

感谢分享~ :xhj003:

不用了,已经解决问题了。

哈哈,你开心就好