提示:如果官网是英文页面,建议使用谷歌浏览器能同步翻译页面。点击下载【谷歌浏览器最新绿色便携版】
注意:部分文章发布时间较长,可能存在未知因素,购买时建议在本站搜索商家名称,先充分了解商家动态。
交流:唯一投稿邮箱:hostvps@88.com。
注意:部分文章发布时间较长,可能存在未知因素,购买时建议在本站搜索商家名称,先充分了解商家动态。
交流:唯一投稿邮箱:hostvps@88.com。
源码:https://github.com/Siujoeng-Lau/WorkersProxy
使用方法: 修改index.js开头的常量, 然后将它部署到cloudflare workers上即可
1、优点:
用Cloudflare Workers加速任意网站, 无需购买或配置服务器
可以用来做静态资源CDN..不用把域名接入cf
可以根据user-agent屏蔽部分地区或ip
可以绑定自定义域名
2、缺点:
Cloudflare Workers一天免费10万次请求
3、具体源码如下:
// Custom domain of your WorkersProxy. const main_domain = 'https://cdn.reverse-proxy.live/' // Subdomain of your Cloudflare Worker. const workers_domain = 'https://google.xasiimov.workers.dev' // Website you intended to retrieve for users. const upstream = 'https://www.google.com/' // Website you intended to retrieve for users using mobile devices. const upstream_mobile = 'https://www.google.com/' // Countries and regions where you wish to suspend your service. const blocked_region = ['CN', 'KP', 'SY', 'PK', 'CU'] // IP addresses which you wish to block from using your service. const blocked_ip_address = ['0.0.0.0', '10.0.0.0'] addEventListener('fetch', event => { event.respondWith(fetchAndApply(event.request)); }) async function fetchAndApply(request) { const region = request.headers.get('cf-ipcountry').toUpperCase(); const ip_address = request.headers.get('cf-connecting-ip'); const user_agent = request.headers.get('user-agent'); let response = null; let url = request.url; if (device_status(user_agent)){ url = url.replace(main_domain, upstream); url = url.replace(workers_domain, upstream); } else { url = url.replace(main_domain, upstream_mobile); url = url.replace(workers_domain, upstream_mobile); } if (blocked_region.includes(region)) { response = new Response('Access denied: WorkersProxy is not available in your region yet.', { status: 403 }); } else if(blocked_ip_address.includes(ip_address)){ response = new Response('Access denied: Your IP address is blocked by WorkersProxy.', { status: 403 }); } else{ let method = request.method; let headers = request.headers; response = fetch(url, { method: method, headers: headers }) } return response; } function device_status (userAgentInfo) { var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }
4、index.js的具体配置
网址带上https ://
// 自定义域名 (没有就空着)
const main_domain =
// Workers 域名.
const workers_domain =
// 要加速的网站.
const upstream =
// 要给手机用户加速的网站. (如果没有就跟上面一样)
const upstream_mobile =
// 要屏蔽的地区
const blocked_region = [‘CN’, ‘KP’, ‘SY’, ‘PK’, ‘CU’]
// 要屏蔽的ip
const blocked_ip_address = [‘0.0.0.0’, ‘10.0.0.0’]
转自:https://www.hostloc.com/thread-585504-1-1.html