- 通过简单配置为多个项目设置 webhook,
- 运行
npm start
或node index.js
- 建议搭配 pm2 使服务持久运行
pm2 start index.js --watch --name 'webhooks-server'
config.json
{
"hostname": "0.0.0.0", // 允许任意地址访问,一般不需要修改
"port": "8001", // 服务端口,按需修改
"projects": [
{
"url": "/test-hook", // 如果只有一个站点,可简单写为`/hook`,如果有多个项目,建议命名为'/projectName-hook'这种形式
"cwd": "./test/", // 脚本工作目录,相对于`webhooks-server`所在目录,一般需要修改
"script": "./test/build.sh" // 脚本路径,相对于`webhooks-server`所在目录,一般需要修改
}
]
}
- webhook 地址为
http://youdomain.com/test-hook
- 编辑
/etc/nginx/conf.d/yousite.conf
文件,增加如下规则
location /test-hook {
proxy_pass http://127.0.0.1:8001/test-hook;
}
- 执行
nginx -s reload
,重启 nginx 生效
-
webhook 地址为
http://youdomain.com:8001/test-hook
-
检查要用的端口是否打开
有安全组的服务器,需要添加规则如允许 TCP:8001
需要检查防火墙状态,如果是开启状态,需要添加规则 -
测试端口是否打开
服务器运行 webhooks-server 后,执行netstat -ntlp
可看到端口监听状态
然后在本机上执行telnet IP PORT
,如果回应中有connected
,则表示端口可以访问