Nginx 配置生成器:自动化反向代理管理 - Openclaw Skills
作者:互联网
2026-04-13
什么是 Nginx 配置生成器?
Nginx 配置生成器是一款企业级自动化技能工具,旨在简化 Web 服务器管理并减少人为错误。通过利用 Openclaw Skills 库中的这一功能,您可以为 Grafana 或自定义 Web 应用等服务以编程方式生成标准化的反向代理配置文件。它通过实施安全检查机制,在应用更改前验证语法,从而消除手动配置错误的风险,确保您的生产环境保持稳定且可访问。
下载入口:https://github.com/openclaw/skills/tree/main/skills/xieyuanqing/nginx-config-creator
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install nginx-config-creator
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 nginx-config-creator。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
Nginx 配置生成器 应用场景
- 在 Nginx 或 OpenResty 反向代理后部署新的 Web 服务。
- 为 Docker 托管的应用自动化域名和端口映射。
- 通过自动安全检查减少服务器配置更新期间的停机时间。
- 在多个微服务或环境中标准化 Nginx 配置模式。
- 从命令行参数和环境变量中收集包括服务名称、域名和端口在内的配置参数。
- 在目标 Nginx 配置目录中生成标准化的 .conf 文件。
- 在指定的 Docker 容器内使用 nginx -t 命令执行安全测试,以确保语法有效性。
- 根据测试结果做出决策:如果测试通过,则重新加载 Nginx;如果失败,则自动删除无效文件以防止服务器故障。
- 向用户报告最终结果,包括详细的执行日志或具体的错误消息。
Nginx 配置生成器 配置指南
要开始使用这些 Openclaw Skills,请确保您已安装 bash 和 docker。为了获得最佳体验,请在 shell 配置文件中预设环境变量:
export NGINX_CONFIG_PATH="/etc/nginx/conf.d"
export NGINX_CONTAINER_NAME="nginx-proxy"
然后,您可以直接通过 CLI 运行脚本:
bash skills/nginx-config-creator/scripts/create-and-reload.sh r
--service-name "myapp" r
--domain "example.com" r
--port "8080"
Nginx 配置生成器 数据架构与分类体系
| 参数 | 描述 | 是否必填 |
|---|---|---|
| --service-name | 服务的短名称(例如:grafana) | 是 |
| --domain | 用于 server_name 指令的根域名 | 是 |
| --port | 服务运行的本地端口 | 是 |
| --config-path | Nginx conf.d 目录的绝对路径 | 可选 |
| --container-name | 正在运行的 Nginx Docker 容器名称 | 可选 |
name: nginx-config-creator
description: "Creates a standard Nginx/OpenResty reverse proxy config file for a service and reloads the web server. Features safety checks and environment awareness. Takes service name, domain, and port as main arguments."
metadata:
openclaw:
requires:
bins: ["bash", "docker"]
Nginx Config Creator (Enterprise Grade)
This skill automates the creation of Nginx/OpenResty reverse proxy configurations. It is designed for both ease of use and safety, incorporating environment awareness and a critical safety-check mechanism.
Features
- Environment Awareness: Simplifies commands by reading configuration from environment variables.
- Safety Check: Includes a '熔断' (fuse) mechanism. It tests the configuration before applying it and automatically rolls back if the test fails, preventing web server downtime.
Pre-requisites (Recommended)
For maximum convenience, it is recommended to set the following environment variables on the host system:
NGINX_CONFIG_PATH: The absolute path to the Nginxconf.ddirectory.NGINX_CONTAINER_NAME: The name of the running Nginx/OpenResty Docker container.
If these are not set, they must be provided as command-line arguments.
Core Action: scripts/create-and-reload.sh
This script performs the entire operation.
Inputs (Command-Line Arguments)
--service-name: (Required) The short name for the service (e.g.,grafana).--domain: (Required) The root domain name (e.g.,example.com).--port: (Required) The local port the service is running on (e.g.,3000).--config-path: (Optional) The path to Nginx'sconf.ddirectory. Overrides theNGINX_CONFIG_PATHenvironment variable.--container-name: (Optional) The name of the Nginx Docker container. Overrides theNGINX_CONTAINER_NAMEenvironment variable.
Output
- On Success: Prints a step-by-step log of its actions and a final success message.
- On Failure: Prints a descriptive error message to stderr and exits. If the failure occurs during the Nginx configuration test, the full error from
nginx -tis displayed.
Execution Workflow
- Parse Arguments & Environment: The script gathers all necessary paths and names from command-line arguments and environment variables.
- Generate Config: It creates the
.conffile in the target directory. - Test Config (Safety Check): It executes
nginx -tinside the specified container. - Decide & Act:
- If the test passes, it proceeds to reload Nginx via
nginx -s reload. - If the test fails, it automatically deletes the generated file (rolls back) and reports the error.
- If the test passes, it proceeds to reload Nginx via
- Report Result: Informs the user of the final outcome.
Example Usage
Scenario 1: Environment variables are pre-set
# Set for future convenience
export NGINX_CONFIG_PATH="/path/to/your/nginx/conf.d"
export NGINX_CONTAINER_NAME="your_nginx_container"
# Now, the command is very simple:
bash skills/nginx-config-creator/scripts/create-and-reload.sh r
--service-name "grafana" r
--domain "example.com" r
--port "3000"
Scenario 2: No environment variables (providing all info via arguments)
bash skills/nginx-config-creator/scripts/create-and-reload.sh r
--service-name "grafana" r
--domain "example.com" r
--port "3000" r
--config-path "/path/to/your/nginx/conf.d" r
--container-name "your_nginx_container"
Failure Strategy
- Missing Arguments: The script will exit with an error if required arguments/environment variables are missing.
nginx -tFails: The skill is designed to be safe. It will not attempt to reload a broken configuration. It will clean up after itself and show you the exact error, ensuring the live web server is never affected.
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
阿里云大模型服务平台百炼新人免费额度如何申请?申请与使用免费额度教程及常见问题解答
办公 AI 工具 OpenClaw 部署 Windows 系统一站式教程
Qwen3.6 正式发布!阿里云百炼同步开启“AI大模型节省计划”超值优惠
【新手零难度操作 】OpenClaw 2.6.4 安装误区规避与快速使用指南(包含最新版安装包)
OpenClaw 2.6.4 可视化部署 打造个人 AI 数字员工(包含最新版安装包)
【小白友好!】OpenClaw 2.6.4 本地 AI 智能体快速搭建教程(内有安装包)
零基础部署 OpenClaw v2.6.2,Windows 系统完整教程
【适合新手的】零基础部署 OpenClaw 自动化工具教程
开发者们的第一台自主进化的“爱马仕”来了
极简部署 OpenClaw 2.6.2 本地 AI 智能体快速启用(含最新版安装包)
AI精选
