HTTP/HTTPS proxy with rules engine and web UI
Project description
UProxier · 代理服务器
基于 mitmproxy 的完整代理软件解决方案,支持 HTTP/HTTPS 代理、请求拦截、规则配置和 Web 界面。
功能特性
- 🔄 HTTP/HTTPS 代理: 完整代理,支持 HTTPS 解密开关
- 🛡️ 证书管理: 自动生成/校验/安装 mitmproxy CA 证书
- 📋 规则引擎: 多动作叠加、优先级、命中短路
- mock_response / modify_headers / modify_content / redirect
- delay_response / conditional_response
- 💾 持久化: 可将抓到的请求以 JSONL 持久化
- 🌐 Web 界面: 实时流量、点击行查看详情、搜索、清空
- 🎯 CLI 工具: start/init/cert/version/examples & 静默模式
- 📊 抓包控制: 流媒体/大文件开关、阈值与二进制保存控制
- 🔧 配置管理: YAML 配置 + CLI 覆盖
安装
pip install uproxier
依赖要求
- Python 3.8+
- OpenSSL (用于证书生成)
快速开始
1. 启动代理
uproxier start
首次启动会自动在用户目录生成 ~/.uproxier/ CA 证书。
2. 安装证书
Web 界面下载:打开 Web 界面右上角"扫码下载证书",移动设备用浏览器访问下载链接安装。
命令行安装:
uproxier cert
# 选择安装到系统,或按提示手动安装
3. 配置代理
在浏览器/设备中配置代理设置:
- 代理地址:
<本机IP> - 端口:
8001
使用说明
命令行工具
主要命令
启动代理服务器
uproxier start \
--host 0.0.0.0 \ # 代理服务器监听地址
--port 8001 \ # 代理服务器端口
--web-port 8002 \ # Web 界面端口
--config <path> \ # 配置文件路径
--save ./logs/traffic.jsonl \ # 保存请求数据到文件
--save-format jsonl \ # 保存格式
--enable-https \ # 启用 HTTPS 解密
--disable-https \ # 禁用 HTTPS 解密
--silent # 静默模式
--daemon # 后台模式启动
证书管理
uproxier cert # 管理证书(生成、安装、清理)
服务器控制
uproxier status # 查看服务器状态
uproxier stop # 停止后台运行的服务器
规则示例管理
uproxier examples --list # 列出所有可用示例
uproxier examples --readme # 显示示例说明文档
uproxier examples --show <文件名> # 显示指定示例内容
uproxier examples --copy <文件名> # 复制示例到当前目录
其他命令
uproxier --verbose # 详细输出
uproxier --version # 显示版本信息
uproxier --help # 显示帮助信息
API 使用
UProxier 提供了完整的 Python API,支持阻塞和非阻塞两种启动方式。
快速示例
阻塞启动:
from proxy_server import ProxyServer
proxy = ProxyServer("config.yaml")
proxy.start("127.0.0.1", 8001, 8002) # 阻塞启动
异步启动:
from proxy_server import ProxyServer
proxy = ProxyServer("config.yaml", silent=True)
proxy.start_async("127.0.0.1", 8001, 8002) # 非阻塞启动
# 继续执行其他代码...
proxy.stop()
详细文档
完整的 API 使用指南请参考:API_USAGE.md
包含:
- 阻塞启动 vs 异步启动的使用场景
- 完整的参数说明和示例
- 进程管理和状态检查
- 错误处理和最佳实践
- 测试和自动化场景示例
规则配置
项目支持在 config.yaml 中定义规则,包含请求/响应修改、Mock、延迟等。
基本规则结构
- name: 规则名称
enabled: true
priority: 100
stop_after_match: false
match:
host: "^api\\.example\\.com$"
path: "^/v1/data$"
method: "GET"
request_pipeline: [] # 请求阶段动作
response_pipeline: # 响应阶段动作
- action: mock_response
params:
status_code: 200
content: '{"status": "success"}'
常用动作
请求阶段 (request_pipeline)
set_header: 设置请求头remove_header: 删除请求头rewrite_url: URL 重写redirect: 重定向请求
响应阶段 (response_pipeline)
mock_response: 完全替换响应set_status: 设置状态码set_header: 设置响应头replace_body: 响应体替换delay: 延迟响应
查看示例
uproxier examples --list # 列出所有示例
uproxier examples --readme # 查看示例说明
uproxier examples --copy 01_set_header.yaml # 复制示例
Web 界面
访问 http://<本机IP>:8002 查看 Web 界面,功能包括:
- 📊 实时流量统计
- 📋 请求/响应详情
- 🔍 流量搜索
- 💾 数据导出
证书管理
自动安装
uproxier cert
# 选择 "安装证书到系统"
手动安装
⚠️ 重要提醒:只安装证书文件,不要安装包含私钥的文件!
证书文件位置:~/.uproxier/
mitmproxy-ca-cert.pem- PEM 格式证书(推荐)mitmproxy-ca-cert.der- DER 格式证书
安装命令:
# macOS
security add-trusted-cert -d -r trustRoot -k ~/Library/Keychains/login.keychain ~/.uproxier/mitmproxy-ca-cert.pem
# Windows
certutil -addstore -f ROOT ~/.uproxier/mitmproxy-ca-cert.der
# Linux
sudo cp ~/.uproxier/mitmproxy-ca-cert.pem /usr/local/share/ca-certificates/mitmproxy-ca.crt
sudo update-ca-certificates
故障排除
常见问题
-
安装后 uproxier 命令不可用
# 如果使用 pyenv,检查版本设置 pyenv global 3.10.6 # 替换为你的 Python 版本 # 确保 Python bin 目录在 PATH 中 export PATH="$(python3 -c "import sys; print(sys.executable.replace('python3', ''))"):$PATH"
-
证书错误
- 确保证书已正确安装到系统
- 重新生成证书:
uproxier cert
-
端口被占用
- 使用不同的端口:
uproxier start --port 8003
- 使用不同的端口:
-
规则不生效
- 检查规则配置是否正确
- 确认规则已启用
- 查看日志输出
-
HTTPS 连接失败
- 确保证书已安装
- 检查浏览器代理设置
许可证
MIT License
参考
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uproxier-0.1.3.tar.gz.
File metadata
- Download URL: uproxier-0.1.3.tar.gz
- Upload date:
- Size: 64.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cb6861d1c7499d1d65ff25028d19d0faf6a1fb102e3cac425396f6584e336a3
|
|
| MD5 |
7c07f12784d69a7b383085a542b2e20f
|
|
| BLAKE2b-256 |
203a8a62afa6604e3d8a5f313b78e749710572f81811bb7a2f925c50b73083c3
|
File details
Details for the file uproxier-0.1.3-py3-none-any.whl.
File metadata
- Download URL: uproxier-0.1.3-py3-none-any.whl
- Upload date:
- Size: 66.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4846615708d3f84538c4d11f43fc51b74187545431ed7b40b29b52a853f91faf
|
|
| MD5 |
0894cb8012dd3ca8cdfabba200f255aa
|
|
| BLAKE2b-256 |
7d2f396f0f9f08b6854407dd6e9a22493165938f62ee2d11e38715f0f36aad9f
|