用途
npm-proxy 是一个用于管理 Nginx Proxy Manager(NPM)的技能,通过 NPM 的 REST API 对 NPM 实例进行管理。当用户想要添加新域名、将域名指向某个服务器或端口、启用或禁用主机、删除主机或查看证书时,可以使用该技能。
主要能力
该技能可管理 NPM 的主机、证书和访问列表。具体提供的脚本命令包括:
- 列出所有代理主机:
python scripts/npm_client.py hosts - 获取指定主机详情:
python scripts/npm_client.py host <host_id> - 启用主机:
python scripts/npm_client.py enable <host_id> - 禁用主机:
python scripts/npm_client.py disable <host_id> - 删除主机:
python scripts/npm_client.py delete <host_id> - 列出证书:
python scripts/npm_client.py certs
使用方式
使用前需要设置以下环境变量:
NPM_URL:NPM 实例的 URL(例如 https://npm.example.com)NPM_EMAIL:NPM 管理员邮箱NPM_PASSWORD:NPM 管理员密码
添加新的代理主机
添加新主机目前需直接使用 curl(脚本功能目前较为精简)。POST /api/nginx/proxy-hosts 的示例载荷如下:
{
"domain_names": ["sub.example.com"],
"forward_scheme": "http",
"forward_host": "192.168.1.10",
"forward_port": 8080,
"access_list_id": 0,
"certificate_id": 0,
"ssl_forced": false,
"meta": {
"letsencrypt_email": "",
"letsencrypt_agree": false,
"dns_challenge": false
},
"advanced_config": "",
"locations": [],
"block_exploits": true,
"caching_enabled": false,
"allow_websocket_upgrade": true,
"http2_support": true,
"hsts_enabled": false,
"hsts_subdomains": false
}
启用 SSL(Let's Encrypt)
- 使用
certs命令列出证书,查看是否已存在证书。 - 使用
certificate_id和ssl_forced: true更新主机。
适用场景
适用于需要通过 NPM 的 REST API 自动化管理反向代理配置的场景,例如批量查看主机、临时启用或禁用某个代理主机、删除不再使用的主机、检查已有证书,以及为域名配置 Let's Encrypt SSL。
限制
- 添加新代理主机目前需直接使用
curl调用 API,脚本本身功能较为精简。 - 关于访问列表的具体管理命令、其他未列出的操作、收费或价格信息,资料中暂未提供。