真沒想到(cloudflare搭建v2ray)cloudflare dns,使用 Cloudflare Workers 解決 OpenAI 和 ChatGPT 的 API 無法訪問的問題,恐怖黎明幽光長(zhǎng)劍在哪,
目錄:
1.搭建v2ray服務(wù)器教程
2.v2rayn服務(wù)器搭建
3.v2rayng 服務(wù)器搭建
4.架設(shè)v2ray服務(wù)器
5.云服務(wù)器v2ray
6.v2ray搭建2021
7.vps v2ray搭建
8.v2ray搭建方法
9.cloudflare加速v2ray
10.搭建v2ray服務(wù)器
1.搭建v2ray服務(wù)器教程
事前準(zhǔn)備你需要將你的沒有被 GFW 域名使用ns的方式轉(zhuǎn)入Cloudflare,否則你將只能使用Cloudflare給你準(zhǔn)備的子域名創(chuàng)建一個(gè) Cloudflare Worker登錄到 Cloudflare 的管理界面后,點(diǎn)擊側(cè)邊欄的 “Workers” 選項(xiàng),點(diǎn)擊 “創(chuàng)建服務(wù)” 創(chuàng)建一個(gè) Work姬神最好聽十首音樂er。
2.v2rayn服務(wù)器搭建
給服務(wù)名稱命名“apiopenai”后選擇“HTTP處理程序”,然后點(diǎn)擊 “創(chuàng)建服務(wù)” 創(chuàng)建一個(gè) Worker。
3.v2rayng 服務(wù)器搭建
創(chuàng)建完成后,其中例圖里的apiopenai.admincmliunet.workers.dev正是由Cloudflare 提供的子域名反代的地址,但是當(dāng)前api反代并未生效,你需要點(diǎn)擊右上角“快速編輯”
4.架設(shè)v2ray服務(wù)器
清空默認(rèn)代碼后將noobnooc大佬g(shù)ithub上cloudflare-worker-proxy.js里的代碼粘貼到至代碼框后點(diǎn)擊“保存并部署”(打不開github也可以直接復(fù)制文章結(jié)尾處的代碼)
5.姬神最好聽十首音樂云服務(wù)器v2ray
此時(shí)已得到由Cloudflare 提供的子域名反代的openai的api地址:apiopenai.admincmliunet.workers.dev接下來添加自己的域名來實(shí)現(xiàn)自己的api地址,返回上一級(jí)選擇“觸發(fā)器”選項(xiàng)點(diǎn)擊“添加自定義域”
6.v2ray搭建2021
在域里填入你接入Cloudflare域名的子域名,例如:我接入的域名是cmliu.cf,所以填入api.cmliu.cf后點(diǎn)擊添加“添加自定義域”后完成
7.vps v2ray搭建
完成此時(shí)你已經(jīng)完成對(duì)api.openai.com的反代設(shè)置Cloudflare Worker每日有10W次的請(qǐng)求量,輕度使用基本用不完,如姬神最好聽十首音樂果你怕麻煩也可以直接使用我生成的反代api地址反代地址:https://api.cmliu.cf。
8.v2ray搭建方法
https://apiopenai.admincmliunet.workers.devnoobnooc大佬的cloudflare-worker-proxy.js代碼// Website you intended to retrieve for users.
9.cloudflare加速v2ray
const upstream = api.openai.com// Custom pathname for the upstream website. const upstream姬神最好聽十首音樂_path =
10.搭建v2ray服務(wù)器
/// Website you intended to retrieve for users using mobile devices. const upstream_mobile = upstream
// Countries and regions where you wish to suspend your service. const blocked_region = [] // IP addresses which you wish to block from using your service.
const 姬神最好聽十首音樂blocked_ip_address = [0.0.0.0, 127.0.0.1] // Whether to use HTTPS protocol for upstream address.
const https = true// Whether to disable cache. const disable_cache = false// Replace texts. const
replace_dict = { $upstream: $custom_domain, } addEven姬神最好聽十首音樂tListener(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 = new URL(request.url); let url_hostname = url.hostname; if (https == true) { url.protocol =
https:; } else { url.protocol = http:; 姬神最好聽十首音樂 } if (await device_status(user_agent)) { var
upstream_domain = upstream; } else { var upstream_domain = upstream_mobile; } url.host = upstream_domain;
if (url.pathname == /) { url.pathname = upstream_path; 姬神最好聽十首音樂 } else { url.pathname = upstream_path + url.pathname; }
if (blocked_region.includes(region)) { response = new Response(Access denied: WorkersProxy is not available in your region yet.
, { status: 403 }); } elseif (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 request_headers = request.headers; let 姬神最好聽十首音樂new_request_headers =
new Headers(request_headers); new_request_headers.set(Host, upstream_domain); new_request_headers.
set(Referer, url.protocol + // + url_hostname); let original_response = await fetch(url.href, { method: method, headers: 姬神最好聽十首音樂new_request_headers, body: request.body }) connection_upgrade = new_request_headers.
get("Upgrade"); if (connection_upgrade && connection_upgrade.toLowerCase() == "websocket") {
return original_response; } let original_response_cl姬神最好聽十首音樂one = original_response.clone(); let original_text =
null; let response_headers = original_response.headers; let new_response_headers = new Headers(response_headers);
let status = original_response.status; if (disable_cache) { new_response_he姬神最好聽十首音樂aders.set(Cache-Control
, no-store); } new_response_headers.set(access-control-allow-origin, *); new_response_headers.
set(access-control-allow-credentials, true); new_response_headers.delete(content-security-policy); new_response_headers.del姬神最好聽十首音樂ete(
content-security-policy-report-only); new_response_headers.delete(clear-site-data); if (new_response_headers.
get("x-pjax-url")) { new_response_headers.set("x-pjax-url", response_headers.get("x-pjax-url").replace(
"http://" + upstream_domain, "http://" + url_hostname)); 姬神最好聽十首音樂 } const content_type = new_response_headers.get
(content-type); if (content_type != null && content_type.includes(text/html) && content_type.includes(
UTF-8)) { original_text = await replace_response_text(original_response_clone, upstream_domain, url_host姬神最好聽十首音樂name); }
else { original_text = original_response_clone.body } response = new Response(original_text, { status, headers: new_response_headers }) }
return response; } async function r姬神最好聽十首音樂eplace_response_text(response, upstream_domain, host_name)
{ let text = await response.text() var i, j; for (i in replace_dict) { j = replace_dict[i]
if (i == $upstream) { i = upstream_domain } elseif (i == $custom_domain) { 姬神最好聽十首音樂 i = host_name }
if (j == $upstream) { j = upstream_domain } elseif (j == $custom_domain) { j = host_name }
let re = new RegExp(i, g) text = text.replace(re, j); } return text; } 姬神最好聽十首音樂 async function
device_status(user_agent_info) { var agents = ["Android", "iPhone", "SymbianOS", "Windows Phone",
"iPad", "iPod"]; var flag = true; for (var v = 0; v
0) { flag = false; break; } } return fl姬神最好聽十首音樂ag; }