众所周知,给网站套上 cloudflare 之后,在国内访问非常拉跨。试试Cloudflare IP优选,让Cloudflare在国内再也不是减速器!
风险提示
目前cf已禁止优选ip行为 (「禁止」cloudflare 代理域的流量被发送到未由 cloudflare 为该域分配的ip地址)
但是目前还没有听说谁被封了,请各位权衡弊利后再优选
如果你觉得有风险,可以去看看 EdgeOne 的优选
使用 cf worker 优选
首先,创建一个Cloudflare Worker,写入代码
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
| const domain_mappings = { '源站.com': '最终访问头.',
};
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); });
async function handleRequest(request) { const url = new URL(request.url); const current_host = url.host;
if (url.protocol === 'http:') { url.protocol = 'https:'; return Response.redirect(url.href, 301); }
const host_prefix = getProxyPrefix(current_host); if (!host_prefix) { return new Response('Proxy prefix not matched', { status: 404 }); }
let target_host = null; for (const [origin_domain, prefix] of Object.entries(domain_mappings)) { if (host_prefix === prefix) { target_host = origin_domain; break; } }
if (!target_host) { return new Response('No matching target host for prefix', { status: 404 }); }
const new_url = new URL(request.url); new_url.protocol = 'https:'; new_url.host = target_host;
const new_headers = new Headers(request.headers); new_headers.set('Host', target_host); new_headers.set('Referer', new_url.href);
try { const response = await fetch(new_url.href, { method: request.method, headers: new_headers, body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body : undefined, redirect: 'manual' });
const response_headers = new Headers(response.headers); response_headers.set('access-control-allow-origin', '*'); response_headers.set('access-control-allow-credentials', 'true'); response_headers.set('cache-control', 'public, max-age=600'); response_headers.delete('content-security-policy'); response_headers.delete('content-security-policy-report-only');
return new Response(response.body, { status: response.status, statusText: response.statusText, headers: response_headers }); } catch (err) { return new Response(`Proxy Error: ${err.message}`, { status: 502 }); } }
function getProxyPrefix(hostname) { for (const prefix of Object.values(domain_mappings)) { if (hostname.startsWith(prefix)) { return prefix; } } return null; }
|
然后创建路由

像这样填写
最后写一条DNS解析,CNAME blog.airtouch.top –> 社区优选域名(见下)
1 2 3 4
| cf.090227.xyz # 来自网络 yx.887141.xyz # 来自网络 acjp2.cloudflarest.link # KJKKK 维护 achk.cloudflarest.link # KJKKK 维护
|
原始优选法
由于该方法已经过时,可以看其他大佬的文章。
写在最后
参考文章:试试Cloudflare IP优选!让Cloudflare在国内再也不是减速器!