基于 nginx 的 Docker 容器化 webhook 反向代理服务,用于接收 GitLab、Jenkins、GitHub、Gitea 等 CI/CD 系统的 webhook 请求,并转发给后端服务(如 openclaw)。
- 支持 GitLab、Jenkins、GitHub、Gitea 等多种 webhook 源
- 基于 nginx 的高性能反向代理
- Docker 容器化部署,开箱即用
- 保留原始 webhook 头部信息
- 健康检查端点
- 访问日志记录
- 安全头部配置
GitLab/Jenkins/GitHub/Gitea → Nginx 反向代理 (Docker) → Openclaw 服务
git clone https://github.com/wanghehacker/webhook_proxy.git
cd webhook_proxy复制环境变量模板并编辑:
cp .env.example .env编辑 .env 文件,配置以下关键参数:
# 代理服务端口(默认 8080)
WEBHOOK_PROXY_PORT=8080
# Openclaw 服务地址和端口
OPENCLAW_HOST=your-openclaw-host
OPENCLAW_PORT=8080
# Webhook 令牌(可选,用于安全验证)
GITLAB_WEBHOOK_TOKEN=your-gitlab-token
JENKINS_WEBHOOK_TOKEN=your-jenkins-token
GENERIC_WEBHOOK_API_KEY=Bearer your-api-keydocker-compose up -d# 健康检查
curl http://localhost:8080/health
# 应返回: healthy服务提供以下 webhook 端点:
| 端点 | 用途 | 推荐认证方式 |
|---|---|---|
/webhooks/gitlab |
GitLab webhooks | X-Gitlab-Token 头 |
/webhooks/jenkins |
Jenkins webhooks | X-Jenkins-Token 头 |
/webhooks/github |
GitHub webhooks | X-Hub-Signature-256 头 |
/webhooks/gitea |
Gitea webhooks | X-Gitea-Signature 头 |
/webhooks/generic |
通用 webhook | Authorization 头 |
/health |
健康检查 | 无 |
- 进入项目 Settings → Webhooks
- 添加 URL:
http://your-proxy-host:8080/webhooks/gitlab - (可选)配置 Secret token
- 选择要触发的事件(Push events, Merge requests 等)
- 点击 "Add webhook"
- 安装 "Notification" 插件或使用构建后操作
- 配置通知 URL:
http://your-proxy-host:8080/webhooks/jenkins - (可选)添加 token 认证
- 保存配置
- 进入仓库 Settings → Webhooks → Add webhook
- Payload URL:
http://your-proxy-host:8080/webhooks/github - Content type:
application/json - Secret: 配置你的 webhook secret
- 选择事件类型
- 点击 "Add webhook"
- 进入仓库 Settings → Webhooks → Add webhook
- Target URL:
http://your-proxy-host:8080/webhooks/gitea - HTTP Method: POST
- 配置 Webhook Secret
- 选择触发事件
- 点击 "Add webhook"
curl -X POST http://localhost:8080/webhooks/gitlab \
-H "X-Gitlab-Token: your-gitlab-token" \
-H "X-Gitlab-Event: Push Hook" \
-H "Content-Type: application/json" \
-d '{"project":{"name":"test"},"ref":"main"}}'curl -X POST http://localhost:8080/webhooks/jenkins \
-H "X-Jenkins-Token: your-jenkins-token" \
-H "Content-Type: application/json" \
-d '{"build":{"full_url":"http://jenkins/job/test/1"}}'curl -X POST http://localhost:8080/webhooks/github \
-H "X-Hub-Signature-256: sha256=..." \
-H "X-GitHub-Event: push" \
-H "Content-Type: application/json" \
-d '{"repository":{"name":"test"},"ref":"refs/heads/main"}}'curl -X POST http://localhost:8080/webhooks/generic \
-H "Authorization: Bearer your-api-key" \
-H "X-Webhook-Source: test-system" \
-H "Content-Type: application/json" \
-d '{"test": "data"}'docker-compose logs -ftail -f logs/access.logtail -f logs/error.logdocker-compose downdocker-compose restart修改 nginx 配置后重启:
docker-compose restartdocker-compose ps- 检查 openclaw 服务是否运行
- 验证
.env中的OPENCLAW_HOST和OPENCLAW_PORT配置 - 检查网络连通性
# 测试到 openclaw 的连通性
docker-compose exec nginx-webhook-proxy ping openclaw- 检查 webhook token 是否正确
- 验证请求头名称是否正确
- 查看 nginx 错误日志
docker-compose logs nginx-webhook-proxy- 增加
nginx/conf.d/webhooks.conf中的超时值 - 检查防火墙规则
- 验证 openclaw 服务响应速度
- 验证配置文件语法:
docker-compose exec nginx-webhook-proxy nginx -t - 检查文件挂载是否正确
- 重启容器
- 使用强随机 token:为每个 webhook 源生成强随机 token
- 不要提交 .env 文件:
.env包含敏感信息,不应提交到 git - 使用 HTTPS:生产环境建议启用 SSL/TLS
- 限制访问源:在防火墙层面限制只允许 CI/CD 系统的 IP 访问
- 定期更新:定期更新 nginx 镜像以获取安全补丁
- 监控日志:定期检查日志以发现异常活动
要启用 HTTPS,需要:
- 在
nginx/ssl/目录放置证书文件 - 修改
nginx/conf.d/webhooks.conf添加 SSL 配置
示例 SSL 配置:
server {
listen 443 ssl http2;
server_name your-domain.com;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# ... 其他配置
}
# HTTP to HTTPS redirect
server {
listen 80;
return 301 https://$host$request_uri;
}然后更新 docker-compose.yml 添加 443 端口映射。
webhook_proxy/
├── nginx/
│ ├── conf.d/
│ │ └── webhooks.conf # Webhook 路由配置
│ ├── nginx.conf # Nginx 基础配置
│ └── ssl/ # SSL 证书目录
├── logs/ # 日志目录
├── docker-compose.yml # Docker 编排文件
├── .env.example # 环境变量模板
├── .gitignore # Git 忽略规则
└── README.md # 项目文档
MIT License
欢迎提交 Issue 和 Pull Request!