{"id":31664028,"url":"https://github.com/bestzwei/ciao-cors","last_synced_at":"2025-10-07T20:53:39.569Z","repository":{"id":308768133,"uuid":"1033814994","full_name":"bestZwei/ciao-cors","owner":"bestZwei","description":"Ciao ~ CORS ^v^: This is a Deno reverse proxy which adds CORS headers to the proxied request.","archived":false,"fork":false,"pushed_at":"2025-08-17T05:16:35.000Z","size":461,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-17T07:07:24.251Z","etag":null,"topics":["cors","cors-anywhere","cors-proxy","deno","proxy"],"latest_commit_sha":null,"homepage":"https://cors.ciao.su","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bestZwei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security-check.sh","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-07T11:42:07.000Z","updated_at":"2025-08-17T05:16:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"8be44136-7b12-479d-b223-2017d6702afe","html_url":"https://github.com/bestZwei/ciao-cors","commit_stats":null,"previous_names":["bestzwei/ciao-cors"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bestZwei/ciao-cors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestZwei%2Fciao-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestZwei%2Fciao-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestZwei%2Fciao-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestZwei%2Fciao-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bestZwei","download_url":"https://codeload.github.com/bestZwei/ciao-cors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestZwei%2Fciao-cors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278846348,"owners_count":26056090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cors","cors-anywhere","cors-proxy","deno","proxy"],"created_at":"2025-10-07T20:53:38.665Z","updated_at":"2025-10-07T20:53:39.564Z","avatar_url":"https://github.com/bestZwei.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CIAO-CORS\n\n高性能、功能完整的CORS代理服务，支持多种部署方式和丰富的配置选项。专为需要跨域资源访问的Web应用设计，提供了安全、可靠的代理解决方案。\n\n🌐 **在线演示**: [cors.ciao.su](https://cors.ciao.su)\n\n感谢 **[DreamCloud](https://whmcs.as211392.com)** 提供的高防服务器支持，为本项目提供稳定可靠的演示环境。\n\n## 功能特性\n\n### 核心功能\n- 🚀 **高性能CORS代理**：支持所有HTTP方法和内容类型，轻松解决跨域问题\n- 🔒 **安全防护**：IP/域名黑白名单、恶意URL检测、请求验证\n- ⚡ **智能限流**：动态请求频率限制和并发控制，防止资源滥用\n- 📊 **实时监控**：详细的请求统计、性能分析和状态监控\n- 🎯 **智能缓存**：GET请求响应缓存，大幅提升性能和减少外部请求\n- 📝 **完整日志**：支持控制台和Webhook日志，便于追踪和分析\n- 🤖 **智能伪装**：优先转发真实User-Agent，自动添加浏览器标准头部，降低被识别为爬虫的风险\n- 🔄 **自动重试**：智能重试机制，自动处理网络波动和临时错误，大幅提升请求成功率\n\n### 配置选项\n- **黑白名单**：支持IP和域名级别的访问控制，精确管理代理权限\n- **频率限制**：可配置的滑动窗口请求限制，自动防御恶意流量\n- **并发控制**：单IP和全局并发数限制，确保系统稳定\n- **统计监控**：可选的请求统计和性能监控，实时了解系统状态\n- **API管理**：内置管理API，支持API密钥保护，安全管理系统\n\n### 部署方式\n- **Deno Deploy**：一键部署到全球CDN网络，极速响应全球请求\n- **VPS部署**：完整的一键安装和管理脚本，轻松管理自己的实例\n- **Docker容器**：支持容器化部署，快速集成到现有基础设施\n\n## 快速开始\n\n### Deno Deploy部署\n\n1. **克隆项目**\n   ```bash\n   git clone https://github.com/bestZwei/ciao-cors.git\n   cd ciao-cors\n   ```\n\n2. **创建Deno Deploy项目**\n   - 访问 [Deno Deploy](https://dash.deno.com)\n   - 创建新项目\n   - 选择\"从GitHub部署\"，选择您的仓库和server.ts文件\n\n3. **配置环境变量**\n   - 在Deno Deploy控制台中设置环境变量（可选）\n   - 可以配置API_KEY、限流参数、域名黑白名单等\n\n4. **开始使用**\n   - 通过 `https://your-project.deno.dev/example.com/api/endpoint` 格式访问\n   - 第一个路径段是您要请求的目标域名和路径\n\n### VPS部署\n\n1. **下载部署脚本**\n   ```bash\n   curl -fsSL https://raw.githubusercontent.com/bestZwei/ciao-cors/main/deploy.sh -o deploy.sh\n   chmod +x deploy.sh\n   ```\n\n2. **运行安装脚本**\n   ```bash\n   sudo ./deploy.sh\n   ```\n\n3. **按照菜单提示操作**\n   - 自动检测和安装Deno\n   - 配置服务参数（端口、API密钥等）\n   - 设置防火墙规则\n   - 创建系统服务\n\n#### 脚本功能特性\n\n- **🔒 安全性**: 脚本锁定机制防止并发执行，完整的权限检查\n- **🌐 兼容性**: 支持Ubuntu、Debian、CentOS、RHEL、Fedora等主流发行版\n- **🔧 智能安装**: 自动检测系统架构，支持x86_64和ARM64\n- **📦 依赖管理**: 自动安装必要依赖，智能包管理器检测\n- **🛡️ 防火墙**: 支持firewalld、ufw、iptables多种防火墙\n- **📋 备份恢复**: 自动备份配置和文件，支持一键恢复\n- **🔄 更新维护**: 内置脚本更新、服务更新、系统优化功能\n- **📊 监控诊断**: 健康检查、性能监控、日志分析\n- **🎯 用户友好**: 彩色输出、详细提示、错误处理\n\n## 高级配置\n\n### 环境变量\n\n| 变量名 | 默认值 | 说明 |\n|--------|--------|------|\n| `PORT` | `3000` | 服务监听端口 |\n| `RATE_LIMIT` | `2500` | 每个时间窗口的最大请求数 |\n| `RATE_LIMIT_WINDOW` | `60000` | 限流时间窗口（毫秒） |\n| `CONCURRENT_LIMIT` | `10` | 单IP最大并发数 |\n| `TOTAL_CONCURRENT_LIMIT` | `1000` | 全局最大并发数 |\n| `MAX_URL_LENGTH` | `2048` | 最大URL长度 |\n| `MAX_BODY_SIZE` | `10485760` | 最大请求体大小（字节，默认10MB） |\n| `TIMEOUT` | `30000` | 请求超时时间（毫秒） |\n| `ENABLE_STATS` | `false` | 是否启用统计功能 |\n| `ENABLE_LOGGING` | `true` | 是否启用日志记录 |\n| `API_KEY` | - | 管理API密钥（可选） |\n| `LOG_WEBHOOK` | - | 日志Webhook URL（可选） |\n| `ALLOWED_ORIGINS` | - | 允许的来源域名列表（JSON或逗号分隔） |\n| `BLOCKED_IPS` | - | 禁止的IP地址列表（JSON或逗号分隔） |\n| `BLOCKED_DOMAINS` | - | 禁止的域名列表（JSON或逗号分隔） |\n| `ALLOWED_DOMAINS` | - | 允许的域名列表（JSON或逗号分隔） |\n| `REQUIRE_HEADERS` | `true` | 是否强制要求Origin或X-Requested-With头部 |\n\n### 配置示例\n\n**基础配置**\n```bash\nexport PORT=3000\nexport RATE_LIMIT=100\nexport ENABLE_STATS=true\nexport API_KEY=your-secret-key\n```\n\n**安全配置**\n```bash\nexport BLOCKED_IPS='[\"192.168.1.100\", \"10.0.0.5\"]'\nexport ALLOWED_DOMAINS='[\"api.example.com\", \"data.example.org\"]'\nexport BLOCKED_DOMAINS='[\"malicious.com\", \"spam.net\"]'\nexport REQUIRE_HEADERS=true  # 强制要求Origin或X-Requested-With头部\n```\n\n**性能配置**\n```bash\nexport CONCURRENT_LIMIT=20\nexport TOTAL_CONCURRENT_LIMIT=2000\nexport TIMEOUT=60000\nexport RATE_LIMIT_WINDOW=30000\n```\n\n## API参考\n\n### 代理使用\n\n**基本代理格式**\n```\nhttps://your-domain.com/{target-url}\n```\n\n**使用示例**\n```bash\n# 代理GET请求（需要添加必需的头部）\ncurl -H \"X-Requested-With: XMLHttpRequest\" \\\n  https://your-domain.com/httpbin.org/get\n\n# 代理POST请求\ncurl -X POST https://your-domain.com/jsonplaceholder.typicode.com/posts \\\n  -H \"Content-Type: application/json\" \\\n  -H \"X-Requested-With: XMLHttpRequest\" \\\n  -d '{\"title\": \"test\", \"body\": \"content\"}'\n\n# 使用Origin头部（浏览器fetch会自动添加）\ncurl -H \"Origin: https://your-app.com\" \\\n  \"https://your-domain.com/api.github.com/users/octocat\"\n```\n\n**JavaScript fetch示例**\n```javascript\n// fetch会自动添加Origin头部，无需手动设置\nfetch('https://your-domain.com/httpbin.org/get')\n  .then(response =\u003e response.json())\n  .then(data =\u003e console.log(data));\n\n// 或者手动添加X-Requested-With头部\nfetch('https://your-domain.com/httpbin.org/get', {\n  headers: {\n    'X-Requested-With': 'XMLHttpRequest'\n  }\n})\n  .then(response =\u003e response.json())\n  .then(data =\u003e console.log(data));\n```\n\n### 管理API\n\n需要设置`API_KEY`环境变量才能访问管理API。\n\n**健康检查**\n```bash\nGET /_api/health?key=your-api-key\n```\n\n**查看统计信息**\n```bash\nGET /_api/stats?key=your-api-key\n```\n\n**查看性能数据**\n```bash\nGET /_api/performance?key=your-api-key\n```\n\n**查看配置信息**\n```bash\nGET /_api/config?key=your-api-key\n```\n\n**查看版本信息**\n```bash\nGET /_api/version?key=your-api-key\n```\n\n**重置统计数据**\n```bash\nGET /_api/reset-stats?key=your-api-key\n```\n\n**清理缓存**\n```bash\nGET /_api/clear-cache?key=your-api-key\n```\n\n**热重载配置**\n```bash\nGET /_api/reload-config?key=your-api-key\n```\n\n**使用Bearer Token**\n```bash\ncurl -H \"Authorization: Bearer your-api-key\" \\\n  https://your-domain.com/_api/stats\n```\n\n## 安全最佳实践\n\n### 🔐 基础安全配置\n\n1. **强制设置API密钥**\n   - 使用至少32位的复杂随机密钥\n   - 包含大小写字母、数字和特殊字符\n   - 定期轮换API密钥（建议每3-6个月）\n   - 示例生成强密钥：`openssl rand -base64 32`\n\n2. **配置严格的访问控制**\n   - 使用域名白名单限制可代理的目标\n   - 配置IP黑名单阻止恶意来源\n   - 设置来源白名单控制CORS访问\n   - 避免使用通配符（*）除非必要\n\n3. **实施多层限流保护**\n   - 请求频率限制：防止单IP过度请求\n   - 并发连接限制：防止资源耗尽\n   - 请求体大小限制：防止大文件攻击\n   - 根据服务器性能调整参数\n\n### 🛡️ 系统安全加固\n\n4. **服务运行安全**\n   - 使用专用非特权用户运行服务\n   - 启用systemd安全特性（已内置）\n   - 配置适当的文件权限（600用于配置文件）\n   - 定期检查服务运行状态\n\n5. **网络安全配置**\n   - 配置防火墙只开放必要端口\n   - 使用HTTPS反向代理（推荐nginx/Apache）\n   - 考虑使用VPN或内网部署\n   - 监控异常网络连接\n\n6. **日志和监控**\n   - 启用详细日志记录\n   - 配置日志轮转防止磁盘满\n   - 设置异常告警（可用Webhook）\n   - 定期分析访问模式\n\n### 🔄 维护和更新\n\n7. **定期安全维护**\n   - 及时更新系统和Deno运行时\n   - 使用管理脚本检查服务状态\n   - 定期备份配置文件\n   - 运行安全检查脚本\n\n8. **安全检查工具**\n   ```bash\n   # 运行安全配置检查\n   curl -fsSL https://raw.githubusercontent.com/bestZwei/ciao-cors/main/security-check.sh | sudo bash\n\n   # 或下载后运行\n   wget https://raw.githubusercontent.com/bestZwei/ciao-cors/main/security-check.sh\n   chmod +x security-check.sh\n   sudo ./security-check.sh\n   ```\n\n### ⚠️ 安全警告\n\n- **永远不要**在生产环境中禁用所有安全限制\n- **永远不要**使用弱密码或默认密钥\n- **永远不要**允许代理访问内网地址（已内置保护）\n- **永远不要**忽略异常的流量模式\n- **定期检查**是否有未授权的配置更改\n\n## 性能优化\n\n### 推荐配置\n- **小型站点**：并发限制10，频率限制60/分钟\n- **中型站点**：并发限制50，频率限制300/分钟\n- **大型站点**：并发限制100，频率限制1000/分钟\n\n### 优化技巧\n1. **增加缓存时间**\n   - 对于不经常变化的内容，可以延长缓存TTL\n   - 添加自定义缓存控制头\n\n2. **调整并发限制**\n   - 对于强CPU服务器，可以增加并发限制\n   - 监控系统负载，避免过载\n\n3. **使用VPS部署脚本的系统优化功能**\n   - 优化系统限制（文件描述符、连接数）\n   - 调整网络参数提高吞吐量\n   - 添加SWAP空间（低内存服务器）\n\n### 监控指标\n- 平均响应时间（目标：\u003c500ms）\n- 错误率（目标：\u003c1%）\n- 并发连接数\n- 缓存命中率（目标：\u003e70%）\n\n## 故障排除\n\n### 部署脚本问题\n\n**Q: 脚本提示\"网络连接失败\"**\n```bash\n# 检查网络连接\nping github.com\nping deno.land\n\n# 检查DNS设置\ncat /etc/resolv.conf\n\n# 临时使用其他DNS\necho \"nameserver 8.8.8.8\" \u003e /etc/resolv.conf\n```\n\n**Q: 健康检查显示\"端口未监听\"但服务在运行**\n```bash\n# 安装网络工具\nsudo apt install net-tools iproute2 lsof  # Ubuntu/Debian\nsudo yum install net-tools iproute lsof   # CentOS/RHEL\n\n# 手动检查端口\nsudo ss -tuln | grep :3000\nsudo netstat -tuln | grep :3000\nsudo lsof -i :3000\n\n# 检查服务日志\nsudo journalctl -u ciao-cors -f\n```\n\n**Q: 性能监控显示\"netstat: command not found\"**\n```bash\n# 现代Linux系统推荐使用ss命令\nsudo apt install iproute2  # Ubuntu/Debian\nsudo yum install iproute   # CentOS/RHEL\n\n# 或安装传统的net-tools\nsudo apt install net-tools  # Ubuntu/Debian\nsudo yum install net-tools  # CentOS/RHEL\n```\n\n**Q: Deno安装失败**\n```bash\n# 手动安装Deno\ncurl -fsSL https://deno.land/x/install/install.sh | sh\nexport PATH=\"$HOME/.deno/bin:$PATH\"\nsudo ln -sf $HOME/.deno/bin/deno /usr/local/bin/deno\n\n# 验证安装\ndeno --version\n```\n\n**Q: 防火墙配置失败**\n```bash\n# 检查防火墙状态\nsudo systemctl status firewalld\nsudo systemctl status ufw\n\n# 手动开放端口\nsudo firewall-cmd --permanent --add-port=3000/tcp\nsudo firewall-cmd --reload\n\n# 或使用ufw\nsudo ufw allow 3000/tcp\n```\n\n**Q: 服务创建失败**\n```bash\n# 检查systemd\nsudo systemctl --version\n\n# 手动重载systemd\nsudo systemctl daemon-reload\n\n# 检查服务文件\nsudo systemctl cat ciao-cors\n```\n\n### 服务运行问题\n\n**Q: 服务启动失败，提示端口被占用**\n```bash\n# 检查端口占用\nsudo netstat -tlnp | grep :3000\nsudo lsof -i :3000\n\n# 或使用其他端口\nsudo ./deploy.sh  # 选择修改配置 -\u003e 端口号\n```\n\n**Q: 请求被拒绝，提示Rate limit exceeded**\n```bash\n# 调整限流配置\nexport RATE_LIMIT=200\nexport RATE_LIMIT_WINDOW=60000\n```\n\n**Q: 代理请求超时**\n```bash\n# 增加超时时间\nexport TIMEOUT=60000\n```\n\n**Q: 统计数据不显示**\n```bash\n# 检查统计功能是否启用\ncurl http://localhost:3000/_api/config?key=your-api-key\n\n# 启用统计功能\nexport ENABLE_STATS=true\n\n# 或修改配置文件\nsudo sed -i 's/^ENABLE_STATS=.*/ENABLE_STATS=true/' /etc/ciao-cors/config.env\nsudo systemctl restart ciao-cors\n\n# 测试统计功能\ncurl https://raw.githubusercontent.com/bestZwei/ciao-cors/main/test-stats.sh | bash\n```\n\n**Q: 客户端收到CORS错误**\n```bash\n# 检查允许的来源设置\nexport ALLOWED_ORIGINS='[\"*\"]'\n# 或者指定特定域名\nexport ALLOWED_ORIGINS='[\"https://your-app.com\"]'\n```\n\n**Q: 收到\"Missing required request header\"错误**\n```bash\n# 这是新的安全功能，需要添加必需的头部\n# 方法1：在请求中添加X-Requested-With头部\ncurl -H \"X-Requested-With: XMLHttpRequest\" https://your-domain.com/target-url\n\n# 方法2：在请求中添加Origin头部\ncurl -H \"Origin: https://your-app.com\" https://your-domain.com/target-url\n\n# 方法3：如果需要禁用此功能（不推荐）\nexport REQUIRE_HEADERS=false\nsudo systemctl restart ciao-cors\n```\n\n### 快速诊断\n\n**使用诊断脚本**\n```bash\n# 下载诊断脚本\ncurl -fsSL https://raw.githubusercontent.com/bestZwei/ciao-cors/main/diagnose.sh -o diagnose.sh\nchmod +x diagnose.sh\n\n# 运行诊断\nsudo ./diagnose.sh\n```\n\n诊断脚本会自动检查：\n- 系统状态和资源\n- 服务运行状态\n- 配置文件有效性\n- 网络连接和端口监听\n- 错误日志分析\n- 提供自动修复建议\n\n### 调试技巧\n\n**查看实时日志**\n```bash\n# systemd服务日志\nsudo journalctl -f -u ciao-cors\n\n# 或者直接运行\ndeno run --allow-net --allow-env server.ts\n```\n\n**API调试**\n```bash\n# 健康检查\ncurl http://localhost:3000/_api/health\n\n# 测试代理\ncurl http://localhost:3000/httpbin.org/ip\n\n# 性能数据\ncurl -H \"Authorization: Bearer your-api-key\" \\\n  http://localhost:3000/_api/performance\n```\n\n## 技术架构\n\nCIAO-CORS 采用现代化的架构设计，确保高性能和可靠性：\n\n- **运行时环境**：使用Deno运行时，获得原生TypeScript支持和安全沙箱\n- **无依赖设计**：不依赖外部npm包，减少安全风险和部署复杂性\n- **内存优化**：智能缓存管理和资源清理，避免内存泄漏\n- **并发控制**：多级限流策略，确保系统稳定性\n- **安全增强**：全面的请求验证和过滤，防止恶意请求\n\n## 许可证\n\nMIT License - 详见 [LICENSE](LICENSE) 文件\n\n## 贡献指南\n\n欢迎提交Issue和Pull Request！\n\n1. Fork本项目\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 开启Pull Request\n\n### 开发环境设置\n\n```bash\n# 安装Deno\ncurl -fsSL https://deno.land/x/install/install.sh | sh\n\n# 本地运行\ndeno run --allow-net --allow-env server.ts\n\n# 类型检查\ndeno check server.ts\n\n# 代码格式化\ndeno fmt server.ts\n\n# 代码lint\ndeno lint server.ts\n```\n\n## 支持\n\n如果这个项目对你有帮助，请给个⭐️！\n\n### 联系方式\n\n- GitHub Issues: [https://github.com/bestZwei/ciao-cors/issues](https://github.com/bestZwei/ciao-cors/issues)\n- Email: [post@zwei.de.eu.org](mailto:post@zwei.de.eu.org)\n\n---\n\nMade with ❤️ by [bestZwei](https://github.com/bestZwei)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestzwei%2Fciao-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbestzwei%2Fciao-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestzwei%2Fciao-cors/lists"}