基於 Cloudflare Workers 的全功能 HTTP/HTTPS 代理服務
- 🌐 多種訪問方式 - Web 介面、查詢參數、路徑方式、標準 HTTP 代理
- 🔒 HTTPS 支援 - 完整支援 HTTPS 網站代理
- 🔄 智能重新導向 - 自動處理 301/302 等重新導向
- 🛠️ 路徑修復 - 自動修復 HTML 中的相對路徑
- 🌍 CORS 支援 - 完整的跨域資源共享支援
- 📱 響應式設計 - 完美適配行動端和桌面端
- ⚡ 零成本運行 - Cloudflare Workers 免費版每天 10 萬次請求
點擊上方 "Deploy to Cloudflare Workers" 按鈕,按照提示完成部署。
# 1. 安裝 Wrangler
npm install -g wrangler
# 2. 登入 Cloudflare
wrangler login
# 3. 複製倉庫
git clone https://github.com/Yrobot/cloudflare-proxy.git
cd cloudflare-proxy
# 4. 部署
wrangler deploy- 登入 Cloudflare Dashboard
- 進入 Workers & Pages
- 點擊 Create Application > Create Worker
- 將
worker.js的內容複製粘貼到編輯器 - 點擊 Save and Deploy
部署成功後,你會獲得一個 Worker URL:
https://your-worker-name.your-subdomain.workers.dev
注意 這個自帶的網域名 Many 區域是無法直接訪問的,建議綁定一個自己的網域名使用
直接訪問你的 Worker URL,在網頁界面輸入目標網址:
https://$YOUR-PROXY-DOMAIN/
在 URL 後添加 ?url= 參數:
https://$YOUR-PROXY-DOMAIN/?url=https://example.com直接在路徑中指定目標網址:
# 完整 URL(帶協定)
https://$YOUR-PROXY-DOMAIN/https://example.com
# 簡寫(自動添加 https://)
https://$YOUR-PROXY-DOMAIN/example.com設定系統代理,適用於命令列工具:
# Linux/macOS
export HTTP_PROXY=https://$YOUR-PROXY-DOMAIN
export HTTPS_PROXY=https://$YOUR-PROXY-DOMAIN
# Windows (PowerShell)
$env:HTTP_PROXY="https://$YOUR-PROXY-DOMAIN"
$env:HTTPS_PROXY="https://$YOUR-PROXY-DOMAIN"
# 使用代理訪問
curl https://api.github.com加速 raw.githubusercontent.com 文件下載:
# 原始地址(可能很慢)
https://raw.githubusercontent.com/user/repo/main/file.txt
# 使用代理(加速訪問)
https://$YOUR-PROXY-DOMAIN/https://raw.githubusercontent.com/user/repo/main/file.txt配置 Docker 鏡像代理源:
# 在 /etc/docker/daemon.json 中配置
{
"registry-mirrors": [
"https://$YOUR-PROXY-DOMAIN/https://registry-1.docker.io"
]
}
# 重啟 Docker
sudo systemctl restart docker代理 OpenAI API 請求:
// 設定代理基礎 URL
const openai = new OpenAI({
baseURL: "https://$YOUR-PROXY-DOMAIN/https://api.openai.com/v1",
apiKey: "your-api-key",
});
// 或使用 fetch
fetch("https://$YOUR-PROXY-DOMAIN/https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer your-api-key",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Hello!" }],
}),
});解決前端跨域問題:
// 直接訪問會遇到 CORS 錯誤
fetch("https://api.example.com/data")
.then((res) => res.json())
.then((data) => console.log(data));
// 使用代理解決 CORS
fetch("https://$YOUR-PROXY-DOMAIN/https://api.example.com/data")
.then((res) => res.json())
.then((data) => console.log(data));在 GitHub Actions 中使用:
jobs:
test:
runs-on: ubuntu-latest
env:
HTTP_PROXY: https://$YOUR-PROXY-DOMAIN
HTTPS_PROXY: https://$YOUR-PROXY-DOMAIN
steps:
- name: Run tests
run: npm test-
使用自定網域名
- Cloudflare 預設的
*.workers.dev網域名在某些地區可能無法訪問 - 強烈建議綁定自己的網域名以獲得更好的訪問體驗
- 在 Worker 設定中點擊 Triggers > Add Custom Domain 增加自定網域名
- Cloudflare 預設的
-
關於請求頭
- 代理會轉發所有請求頭和內容
-
訪問限制
- Cloudflare Workers 免費版每天 10 萬次請求
- 單次請求不能超過 100MB
- CPU 時間限制:免費版 10ms,付費版 50ms
export default {
async fetch(request) {
// 檢查 API Key
const apiKey = request.headers.get("X-API-Key");
if (apiKey !== "your-secret-key") {
return new Response("Unauthorized", { status: 401 });
}
// 原有邏輯...
},
};本專案僅供學習和研究使用,使用者需遵守以下規定:
- 合法使用 - 僅用於訪問合法內容,不得用於訪問違法或侵權內容
- 服務條款 - 使用時需遵守 Cloudflare Workers 服務條款
- 責任自負 - 使用本代理產生的任何後果由使用者自行承擔
- 商業用途 - 如需商業使用,請確保符合相關法規
- 隱私保護 - 建議不要通過代理傳輸個人敏感信息
A: 可能原因:
- 網站有防爬蟲機制,檢測到了代理訪問
- 網站使用了 WebSocket 等 Cloudflare Workers 不支持的協議
- 超過了請求大小或時間限制
A: 建議:
- 使用自定網域名,選擇離用戶更近的 DNS 伺服器
- 對於靜態資源,考慮使用 Cloudflare 的快取功能
A: 不可以。Cloudflare Workers 目前不支持 WebSocket 連接。
欢迎提交 Issue 和 Pull Request!
如果这个项目对你有帮助,请在 GitHub 上给我们一个 ⭐️
