{"id":15523754,"url":"https://github.com/arloor/rust_http_proxy","last_synced_at":"2026-01-31T09:07:30.253Z","repository":{"id":162508928,"uuid":"636987409","full_name":"arloor/rust_http_proxy","owner":"arloor","description":"基于Rust的正向代理、反向代理和静态资源托管。  forward proxy、reverse proxy and static file serving","archived":false,"fork":false,"pushed_at":"2026-01-25T05:43:40.000Z","size":6276,"stargazers_count":52,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-25T19:07:43.719Z","etag":null,"topics":["http-proxy","http-server","reverse-proxy"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arloor.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-06T06:54:21.000Z","updated_at":"2026-01-25T05:43:43.000Z","dependencies_parsed_at":"2025-12-13T06:06:07.269Z","dependency_job_id":null,"html_url":"https://github.com/arloor/rust_http_proxy","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/arloor/rust_http_proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arloor%2Frust_http_proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arloor%2Frust_http_proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arloor%2Frust_http_proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arloor%2Frust_http_proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arloor","download_url":"https://codeload.github.com/arloor/rust_http_proxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arloor%2Frust_http_proxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28936100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T08:53:31.997Z","status":"ssl_error","status_checked_at":"2026-01-31T08:51:38.521Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["http-proxy","http-server","reverse-proxy"],"created_at":"2024-10-02T10:46:48.905Z","updated_at":"2026-01-31T09:07:30.244Z","avatar_url":"https://github.com/arloor.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Rust HTTP Proxy\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/arloor/rust_http_proxy)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/arloor/rust_http_proxy)\n\n一个基于 Rust 构建的高性能、多功能 HTTP 代理服务器，使用 `hyper`、`axum` 和 `rustls` 实现。\n\n## ✨ 核心特性\n\n### 🚀 代理功能\n\n- **正向代理**：支持 HTTP/HTTPS 代理，可通过用户名密码认证\n- **反向代理**：支持灵活配置反向代理路由规则\n- **链式代理**：通过 `--forward-bypass-url` 指定上游代理服务器\n- **websocket**: 正向代理和反向代理均支持websocket\n\n### 📁 静态文件服务\n\n- **类 Nginx 托管**：完整的静态资源托管能力\n- **压缩支持**：自动 gzip 压缩，减少传输流量\n- **断点续传**：支持 Accept-Ranges 和断点续传（单 range）\n- **防盗链**：基于 Referer 请求头的图片防盗链功能\n\n### 🔒 安全与加密\n\n- **TLS 加密代理**：支持 `--over-tls` 参数，对正向代理流量进行 TLS 加密\n- **自动证书加载**：每天自动重新加载 TLS 证书，支持 ACME 证书自动续期，无需重启服务\n- **高匿代理**：完整实现高匿代理，去除代理特征（详见[高匿实现](#高匿实现)）\n\n### 📊 可观测性\n\n- **Prometheus 集成**：提供完整的 Prometheus metrics 导出\n- **网速监控**：Linux 平台支持实时网卡流量监控（`/net` 路径）\n- **eBPF 支持**：可选 eBPF socket filter 进行高性能流量统计\n- **Grafana 大盘**：提供开箱即用的 [Grafana 模板](https://grafana.com/grafana/dashboards/20185-rust-http-proxy/)\n\n### 🔧 其他特性\n\n- **多端口、多用户**：支持同时监听多个端口，配置多个用户认证\n- **连接管理**：10 分钟空闲自动关闭连接，节省资源\n- **跨平台**：支持 Linux、macOS、Windows，提供 Windows 服务模式\n\n## 安装使用\n\n### 方式一：Linux AMD64 可执行文件\n\n```bash\ncurl -SLf https://us.arloor.dev/https://github.com/arloor/rust_http_proxy/releases/download/latest/rust_http_proxy -o /tmp/rust_http_proxy\ninstall /tmp/rust_http_proxy /usr/bin/rust_http_proxy\n/usr/bin/rust_http_proxy -p 7788\n```\n\n### 方式二：Docker 运行（推荐）\n\n```bash\n# 标准版本\ndocker run --rm -it --net host --pid host quay.io/arloor/rust_http_proxy -p 7788\n\n# eBPF 增强版本\ndocker run --rm -it --privileged --net host --pid host quay.io/arloor/rust_http_proxy:bpf_static -p 7788\n```\n\n\u003e 💡 Docker 镜像通过 GitHub Actions 自动构建，始终保持最新版本\n\n### 方式三：从源码编译\n\n```bash\n# 克隆仓库\ngit clone https://github.com/arloor/rust_http_proxy.git\ncd rust_http_proxy\n\n# 标准编译\ncargo build --release\n\n# eBPF 增强版本（需要额外依赖）\ncargo build --release --features bpf_vendored\n```\n\n### 快速测试\n\n启动服务后，使用 curl 测试：\n\n```bash\n# 测试正向代理（HTTP）\ncurl http://ip.im/info -x http://localhost:7788\n\n# 测试正向代理（HTTPS + 认证）\ncurl https://ip.im/info -U \"username:password\" -x https://localhost:7788 --proxy-insecure\n```\n\n## ⚙️ 配置说明\n\n### 命令行参数\n\n```shell\n$ rust_http_proxy --help\nA HTTP proxy server based on Hyper and Rustls, which features TLS proxy and static file serving\n\nUsage: rust_http_proxy [OPTIONS]\n\nOptions:\n      --log-dir \u003cLOG_DIR\u003e\n          [default: /tmp]\n      --log-file \u003cLOG_FILE\u003e\n          [default: proxy.log]\n  -p, --port \u003cPORT\u003e\n          可以多次指定来实现多端口\n           [default: 3128]\n  -c, --cert \u003cCERT\u003e\n          [default: cert.pem]\n  -k, --key \u003cKEY\u003e\n          [default: privkey.pem]\n  -u, --users \u003cUSER\u003e\n          默认为空，表示不鉴权。\n          格式为 'username:password'\n          可以多次指定来实现多用户\n  -w, --web-content-path \u003cWEB_CONTENT_PATH\u003e\n          静态文件托管的根目录\n  -r, --referer-keywords-to-self \u003cREFERER\u003e\n          Http Referer请求头处理\n          1. 图片资源的防盗链：针对png/jpeg/jpg等文件的请求，要求Request的Referer header要么为空，要么包含配置的值\n          2. 外链访问监控：如果Referer不包含配置的值，并且访问html资源时，Prometheus counter req_from_out++，用于外链访问监控\n          可以多次指定，也可以不指定\n      --never-ask-for-auth\n          if enable, never send '407 Proxy Authentication Required' to client。\n          当作为正向代理使用时建议开启，否则有被嗅探的风险。\n      --allow-serving-network \u003cCIDR\u003e\n          允许访问静态文件托管的网段白名单，格式为CIDR，例如: 192.168.1.0/24, 10.0.0.0/8\n          可以多次指定来允许多个网段\n          如未设置任何网段，则允许所有IP访问静态文件\n  -o, --over-tls\n          if enable, proxy server will listen on https\n      --location-config-file \u003cFILE_PATH\u003e\n          静态文件托管和反向代理的配置文件\n      --enable-github-proxy\n          是否开启github proxy\n      --append-upstream-url \u003chttps://example.com\u003e\n          便捷反向代理配置\n          例如：--append-upstream-url=https://cdnjs.cloudflare.com\n          则访问 https://your_domain/https://cdnjs.cloudflare.com 会被代理到 https://cdnjs.cloudflare.com\n      --forward-bypass-url \u003chttps://username:password@example.com:123\u003e\n          指定上游代理服务器\n      --ipv6-first \u003cIPV6_FIRST\u003e\n          优先使用 IPv6 进行连接。true表示IPv6优先，false表示IPv4优先，不设置则保持DNS原始顺序 [possible values: true, false]\n  -h, --help\n          Print help\n```\n\n### 🔐 TLS/SSL 配置\n\n#### 生成自签名证书（测试用）\n\n```bash\nopenssl req -x509 -newkey rsa:4096 -sha256 -nodes \\\n  -keyout /usr/share/rust_http_proxy/privkey.pem \\\n  -out /usr/share/rust_http_proxy/cert.pem \\\n  -days 3650 \\\n  -subj \"/C=cn/ST=hl/L=sd/O=op/OU=as/CN=example.com\"\n```\n\n#### 使用正式证书\n\n生产环境建议使用以下方式获取正式证书：\n\n- 购买商业 TLS 证书\n- 使用 [acme.sh](https://github.com/acmesh-official/acme.sh) 等工具申请 Let's Encrypt 免费证书\n\n### 📂 静态文件托管配置\n\n#### 全局配置\n\n通过 `--web-content-path` 参数指定默认静态资源目录：\n\n```bash\nrust_http_proxy -p 7788 --web-content-path /var/www/html\n```\n\n#### 高级配置（基于域名和路径）\n\n使用 `--location-config-file` 指定 YAML 配置文件，支持按域名、路径分别配置：\n\n```yaml\n# 针对特定域名的配置\nexample.com:\n  - location: / # URL 路径前缀，默认 /\n    static_dir: /usr/share/nginx/html # 静态资源目录\n\n# 对所有域名生效的配置\ndefault_host:\n  - location: /static\n    static_dir: /var/www/static\n  - location: /downloads\n    static_dir: /var/www/downloads\n```\n\n### 🔄 反向代理配置\n\n使用 `--location-config-file` 配置反向代理规则：\n\n```yaml\n# 针对特定域名\napi.example.com:\n  - location: /api\n    upstream:\n      url_base: \"https://backend.internal.com\" # 上游服务器 URL\n      version: \"AUTO\" # HTTP 版本: H1/H2/AUTO\n      headers: # 可选：修改发送给上游的请求头\n        Host: \"#{host}\" # #{host} 变量代表原始请求的 Host\n        X-Custom-Header: \"custom_value\"\n```\n\n反向代理到上游的请求url构建方式如下：\n\n```rust\nlet upstream_url = upstream.url_base.clone() + \u0026path_and_query[location.len()..]; // upstream.url_base + 原始url_path去除location的部分\n```\n\n#### upstream 配置项说明\n\n| 参数       | 说明                        | 可选值                      |\n| ---------- | --------------------------- | --------------------------- |\n| `url_base` | 上游服务器的基础 URL        | 任意有效 URL                |\n| `version`  | HTTP 协议版本               | `H1`、`H2`、`AUTO`（默认）  |\n| `headers`  | 覆盖/添加发送给上游的请求头 | 键值对，支持 `#{host}` 变量 |\n\n### 🌐 内置反向代理功能\n\n#### GitHub 资源代理\n\n在国内无法访问 GitHub 时，可启用 GitHub 代理功能。通过在原始 URL 前添加 `https://YOUR_DOMAIN` 访问：\n\n```bash\n# 启动时添加参数\nrust_http_proxy -p 7788 --enable-github-proxy\n```\n\n支持代理的 GitHub 域名：\n\n- `raw.githubusercontent.com`\n- `github.com`\n- `gist.githubusercontent.com`\n- `gist.github.com`\n- `release-assets.githubusercontent.com`\n- `objects.githubusercontent.com`\n\n使用示例：\n\n```bash\n# 原始地址\nhttps://raw.githubusercontent.com/user/repo/main/file.txt\n\n# 代理后地址\nhttps://YOUR_DOMAIN/https://raw.githubusercontent.com/user/repo/main/file.txt\n```\n\n#### 快捷反向代理\n\n通过 `--append-upstream-url` 快速配置反向代理：\n\n```bash\nrust_http_proxy -p 7788 --append-upstream-url=https://cdnjs.cloudflare.com\n```\n\n访问方式：\n\n```\nhttps://YOUR_DOMAIN/https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js\n```\n\n等价于以下 YAML 配置：\n\n````yaml\n```yaml\ndefault_host:\n  - location: /https://cdnjs.cloudflare.com\n    upstream:\n      url_base: https://cdnjs.cloudflare.com\n      version: AUTO\n````\n\n## 📊 可观测性与监控\n\n### Prometheus Metrics\n\n本项目内置 Prometheus Exporter，通过 `/metrics` 端点暴露指标。\n\n\u003e ⚠️ **注意**：如果设置了 `--users` 参数，访问 `/metrics` 时需要在 HTTP Header 中提供 Authorization，否则返回 `401 UNAUTHORIZED`。\n\n#### 示例指标\n\n```prometheus\n# HELP req_from_out Number of HTTP requests received.\n# TYPE req_from_out counter\nreq_from_out_total{referer=\"all\",path=\"all\"} 4\n\n# HELP proxy_traffic num proxy_traffic.\n# TYPE proxy_traffic counter\nproxy_traffic_total 1048576\n# EOF\n```\n\n### Grafana 可视化\n\n推荐使用官方提供的 [Grafana Dashboard 模板](https://grafana.com/grafana/dashboards/20185-rust-http-proxy/)，快速搭建监控大盘。\n\n**效果预览**：\n\n![Grafana Dashboard 1](grafana-template1.png)\n![Grafana Dashboard 2](grafana-template2.png)\n\n### 实时网速监控（Linux）\n\n在 Linux 平台运行时，访问 `/net` 路径可查看实时网卡流量监控。\n\n**效果预览**：\n\n![网速监控](speed.png)\n\n## 🖥️ 客户端推荐\n\n### Clash 系列\n\n- [clash-verge-rev](https://github.com/clash-verge-rev/clash-verge-rev) - 跨平台 Clash GUI\n- [ClashMetaForAndroid](https://github.com/MetaCubeX/ClashMetaForAndroid) - Android 平台\n- [mihomo (clash-meta)](https://github.com/MetaCubeX/mihomo/tree/Meta) - 核心程序\n\n### 作者自研客户端\n\n- **Rust**: [sslocal](https://github.com/arloor/shadowsocks-rust) - Fork shadowsocks-rust\n- **Golang**: [forward](https://github.com/arloor/forward)\n- **Java**: [connect](https://github.com/arloor/connect)\n\n## 🛠️ 高级功能\n\n### Cargo Features\n\n本项目支持多种编译特性，可根据需求选择：\n\n#### 🔥 eBPF 增强（推荐）\n\n使用 eBPF 技术统计网卡流量，提供更高性能和更详细的网络监控。\n\n**编译方式**：\n\n```bash\ncargo build --release --features bpf_vendored\n```\n\n**系统依赖**：\n\nUbuntu 22.04：\n\n```bash\napt-get install -y libbpf-dev bpftool cmake zlib1g-dev libelf-dev \\\n  pkg-config clang autoconf autopoint flex bison gawk make\n```\n\nCentOS Stream 9：\n\n```bash\nyum install -y libbpf zlib-devel elfutils-libelf-devel pkgconf-pkg-config \\\n  clang bpftool cmake autoconf gettext flex bison gawk make\n```\n\n\u003e ⚠️ **注意**：仅在 `x86_64-unknown-linux-gnu` 平台测试通过\n\n#### 🧠 Jemalloc 内存分配器\n\n使用 jemalloc 替代系统默认内存分配器，提供更好的并发性能和减少内存碎片。\n\n**编译方式**：\n\n```bash\ncargo build --release --features jemalloc\n```\n\n**特点**：\n\n- ✅ 更高的并发分配能力\n- ✅ 减少内存碎片\n- ⚠️ 会缓存更多内存，`top` 命令中 RES 值可能较高\n\n#### 🔐 AWS-LC-RS 加密后端\n\n替换默认的 `ring` 加密库为 AWS 的 `aws-lc-rs`，提供更好的性能和 FIPS 合规性。\n\n**编译方式**：\n\n```bash\ncargo build --release --no-default-features --features aws_lc_rs\n```\n\n**优势**：\n\n1. ⚡ 性能更优（[Benchmark 测试](https://github.com/aochagavia/rustls-bench-results)）\n2. 🏛️ 支持 [FIPS 140-2](https://csrc.nist.gov/pubs/fips/140-2/upd2/final) 合规要求\n\n**额外依赖**：\n\n```bash\napt-get install cmake  # Ubuntu/Debian\nyum install cmake      # CentOS/RHEL\n```\n\n### 高匿代理实现\n\n高匿代理（Elite Proxy）是指能够完全隐藏自身代理身份的代理服务器。本项目完整实现了高匿代理特性。\n\n#### 代理特征清除\n\n普通代理服务器收到的 HTTP 请求具有以下特征，本项目已全部处理：\n\n1. **完整 URL 格式**\n   - ❌ 普通代理：Request Line 包含完整 URL（schema + host + path）\n   - ✅ 高匿处理：转换为仅包含路径的标准格式\n\n2. **Proxy-Connection 请求头**\n   - ❌ 普通代理：保留 `Proxy-Connection` 头\n   - ✅ 高匿处理：自动删除\n\n3. **Proxy-Authorization 请求头**\n   - ❌ 普通代理：保留 `Proxy-Authorization` 头\n   - ✅ 高匿处理：自动删除\n\n#### 验证测试\n\n使用 tcpdump 抓包验证，对比代理服务器和上游服务器收到的请求：\n\n**代理服务器收到的原始请求**：\n\n![代理服务器流量](traffic_at_proxy.png)\n\n**上游 Nginx 服务器收到的处理后请求**：\n\n![Nginx 服务器流量](traffic_at_nginx.png)\n\n✅ **验证结论**：Request URL 已转换为标准路径格式，`Proxy-Connection` 等代理特征头已被移除。\n\n## 🐳 容器化开发\n\n### 本地测试\n\n```bash\n# 清理构建缓存\ncargo clean\n\n# 编译 eBPF 增强版本\ncargo build -r --features bpf_vendored\n\n# 构建测试镜像\npodman build . -f Dockerfile.test -t test --net host\n\n# 运行测试容器\npodman run --rm -it --privileged --net host --pid host test\n```\n\n## 🪟 Windows 服务模式\n\n### 编译 Windows 服务版本\n\n```powershell\ncargo build --bin rust_http_proxy_service --features winservice --release\n```\n\n### 安装与管理\n\n#### 使用 sc.exe\n\n```powershell\n# 创建服务\nsc.exe create rust_http_proxy binPath= \"C:\\path\\to\\rust_http_proxy_service.exe -p 7777 -u username:password\"\n\n# 启动服务\nsc.exe start rust_http_proxy\n\n# 设置自动启动\nsc.exe config rust_http_proxy start= auto\n\n# 停止服务\nsc.exe stop rust_http_proxy\n\n# 删除服务\nsc.exe delete rust_http_proxy\n```\n\n#### 使用 PowerShell Cmdlet\n\n```powershell\n# 创建并配置服务\nNew-Service -Name \"rust_http_proxy\" `\n  -BinaryPathName \"C:\\path\\to\\rust_http_proxy_service.exe -p 7777 -u username:password\" `\n  -StartupType Automatic `\n  -Description \"A HTTP proxy server based on Hyper and Rustls\"\n\n# 启动服务\nStart-Service -Name \"rust_http_proxy\"\n\n# 停止服务\nStop-Service -Name \"rust_http_proxy\"\n\n# 删除服务\n(Get-WmiObject -Class Win32_Service -Filter \"Name='rust_http_proxy'\").Delete()\n\n# PowerShell 6.0+ 可使用\n# Remove-Service -Name \"rust_http_proxy\"\n```\n\n## 📄 许可证\n\n本项目采用双许可证：\n\n- [LGPL-2.1-only](LICENSE.LGPL-2.1) OR [BSD-2-Clause](LICENSE.BSD-2-Clause)\n\n## 🤝 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n## 📮 联系方式\n\n- GitHub Issues: [arloor/rust_http_proxy/issues](https://github.com/arloor/rust_http_proxy/issues)\n- 项目主页: [github.com/arloor/rust_http_proxy](https://github.com/arloor/rust_http_proxy)\n\n---\n\n⭐ 如果这个项目对你有帮助，请给一个 Star！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farloor%2Frust_http_proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farloor%2Frust_http_proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farloor%2Frust_http_proxy/lists"}