configurable-http-proxy(简称CHP)是一个基于https://github.com/nodejitsu/node-http-proxy的动态代理工具,通过命令行界面或REST API实现代理表的更新与管理。它支持WebSocket,适用于构建反向代理、负载均衡器等组件,特别为https://github.com/jupyterhub/jupyterhub部署提供扩展功能。
CHP运行两个HTTP(S)服务器:
--ip和--port控制,默认监听所有网络接口--api-ip和--api-port控制,默认监听本地回环地址,通过CONFIGPROXY_AUTH_TOKEN环境变量进行认证!https://raw.githubusercontent.com/jupyterhub/configurable-http-proxy/main/doc/_static/chp.png
基础启动命令
bashdocker run -d \ --name chp \ -p 8000:8000 \ -p 8001:8001 \ -e CONFIGPROXY_AUTH_TOKEN="your-secure-token" \ jupyterhub/configurable-http-proxy \ --default-target http://localhost:8888 \ --log-level info
带SSL配置的启动命令
bashdocker run -d \ --name chp-ssl \ -p 443:8000 \ -p 8001:8001 \ -v /path/to/ssl:/ssl \ -e CONFIGPROXY_AUTH_TOKEN="your-secure-token" \ jupyterhub/configurable-http-proxy \ --ssl-key /ssl/server.key \ --ssl-cert /ssl/server.crt \ --default-target https://backend-service:443 \ --log-level debug
启动代理
bashconfigurable-http-proxy [选项]
设置默认目标
默认目标用于处理未匹配路由规则的请求:
bashconfigurable-http-proxy --default-target=http://localhost:8888
命令行选项
| 选项 | 描述 |
|---|---|
-V, --version | 输出版本号 |
--ip <ip-address> | 公共接口IP地址(默认监听所有接口) |
--port <n> | 公共接口端口(默认8000) |
--ssl-key <keyfile> | SSL私钥文件路径 |
--ssl-cert <certfile> | SSL证书文件路径 |
--api-ip <ip> | API接口IP地址(默认localhost) |
--api-port <n> | API接口端口(默认port+1) |
--default-target <host> | 默认代理目标(格式:proto://host[:port]) |
--error-target <host> | 错误处理目标服务器 |
--error-path <path> | 本地错误页面目录路径 |
--host-routing | 启用基于主机名的路由 |
--log-level <loglevel> | 日志级别(debug/info/warn/error,默认info) |
--timeout <n> | 请求超时时间(毫秒) |
--proxy-timeout <n> | 目标响应超时时间(毫秒) |
/api/Authorization头传递令牌,格式:Authorization: token <CONFIGPROXY_AUTH_TOKEN>http://localhost:8001(由--api-ip和--api-port控制)| HTTP方法 | 端点 | 功能 |
|---|---|---|
| GET | /api/ | 获取API根信息 |
| GET | /api/routes | 获取当前路由表 |
| POST | /api/routes/{route_spec} | 添加新路由 |
| DELETE | /api/routes/{route_spec} | 删除指定路由 |
bashexport CONFIGPROXY_AUTH_TOKEN="your-secure-token" curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes
bash# 获取所有路由 curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" http://localhost:8001/api/routes # 获取指定时间前未活动的路由 curl -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" "http://localhost:8001/api/routes?inactive_since=2024-01-01T00:00:00Z"
bash# 添加路由:将/path路由到http://localhost:8002 curl -X POST \ -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" \ -H "Content-Type: application/json" \ -d '{"target": "http://localhost:8002"}' \ http://localhost:8001/api/routes/path
bash# 删除/path路由 curl -X DELETE \ -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" \ http://localhost:8001/api/routes/path
通过--error-path指定错误页面目录,CHP会根据状态码加载对应HTML文件:
bashconfigurable-http-proxy --error-path /usr/share/chp-errors
目录结构示例:
/usr/share/chp-errors/ ├── 404.html # 404错误页面 ├── 503.html # 503错误页面 └── error.html # 默认错误页面(当特定状态码文件不存在时使用)
通过--error-target指定错误处理服务器,CHP会将错误请求转发至此服务器:
bashconfigurable-http-proxy --error-target http://localhost:1234
错误请求格式:GET /{状态码}?url={编码后的请求路径},例如:
GET /404?url=%2Fnotebook%2Fuser%2Ftest
启用--host-routing选项后,CHP会根据请求的主机名进行路由选择。API中通过将主机名作为路径前缀来管理路由:
bash# 添加主机路由:将example.com路由到http://localhost:1234 curl -X POST \ -H "Authorization: token $CONFIGPROXY_AUTH_TOKEN" \ -H "Content-Type: application/json" \ -d '{"target": "http://localhost:1234"}' \ http://localhost:8001/api/routes/example.com
CONFIGPROXY_AUTH_TOKEN环境变量是否正确设置GET /api/routesdebug,查看详细请求处理过程--insecure选项禁用证书验证(仅测试环境使用)您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务