# 网络代理 **Repository Path**: smallsource/web-proxy ## Basic Information - **Project Name**: 网络代理 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-01 - **Last Updated**: 2025-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Web 代理服务器 一个简单的 HTTP/HTTPS 代理服务器,可以通过国外服务器代理访问其他网站。 ## 功能特性 - ✅ 支持 HTTP 和 HTTPS 代理 - ✅ 支持 CORS 跨域请求 - ✅ 动态目标 URL 配置 - ✅ 请求日志记录 - ✅ 健康检查端点 - ✅ 错误处理 ## 安装 ```bash npm install ``` ## 配置 复制 `.env.example` 为 `.env` 并根据需要修改: ```bash cp .env.example .env ``` 环境变量说明: - `PORT`: 服务器监听端口(默认: 8080) - `ALLOWED_ORIGINS`: 允许的 CORS 源,多个用逗号分隔,`*` 表示允许所有 ## 运行 ```bash npm start ``` 服务器将在 `0.0.0.0:PORT` 上启动,可以从任何 IP 地址访问。 ## 使用方法 ### 方式一:查询参数方式(推荐) ``` http://your-server-ip:8080/proxy?url=https://www.google.com ``` ### 方式二:路径方式 ``` http://your-server-ip:8080/proxy/https://www.google.com ``` ### 示例 1. **访问 Google** ``` http://your-server-ip:8080/proxy?url=https://www.google.com ``` 2. **访问 GitHub** ``` http://your-server-ip:8080/proxy?url=https://github.com ``` 3. **访问特定页面** ``` http://your-server-ip:8080/proxy?url=https://www.example.com/path/to/page ``` 4. **健康检查** ``` http://your-server-ip:8080/health ``` ## 部署到服务器 ### 1. 上传文件到服务器 使用 scp 或 FTP 工具将项目文件上传到服务器。 ### 2. 安装依赖 ```bash cd /path/to/web-proxy npm install ``` ### 3. 使用 PM2 运行(推荐) ```bash # 安装 PM2 npm install -g pm2 # 启动服务 pm2 start server.js --name web-proxy # 查看状态 pm2 status # 查看日志 pm2 logs web-proxy # 设置开机自启 pm2 startup pm2 save ``` ### 4. 配置防火墙 确保服务器防火墙开放了指定端口(默认 8080): ```bash # Ubuntu/Debian sudo ufw allow 8080/tcp # CentOS/RHEL sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload ``` ### 5. 使用 Nginx 反向代理(可选) 如果需要使用域名和 HTTPS,可以配置 Nginx: ```nginx server { listen 80; server_name your-domain.com; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` ## 注意事项 1. **安全性**:生产环境建议添加身份验证机制 2. **性能**:大量并发请求时考虑使用负载均衡 3. **日志**:定期清理日志文件 4. **合规性**:确保遵守目标网站的使用条款 ## 故障排查 1. **无法连接** - 检查服务器防火墙设置 - 确认端口是否被占用 - 查看服务器日志 2. **代理失败** - 检查目标 URL 是否可访问 - 查看控制台错误信息 - 确认网络连接正常 ## License MIT