在 Nginx 与 HTTPS 后部署 SkillFlaw
在 Linux 服务器上部署 SkillFlaw 时,建议保留现有服务拆分方式,并让 Nginx 作为前置入口层。
本指南默认你采用与 docker/docker-compose.yml 一致的运行契约:
- 后端 API 在
7860 - 前端 UI 在
3001 - 可选的独立文档服务在
3002
由 Nginx 负责对外 HTTPS、主机名路由与请求限制。
适用场景
当你想采用以下这些部署形态时,可以使用本指南:
- 完整 Web 部署:前端 + 后端,文档按需使用独立域名
- API 优先部署:只暴露后端,文档按需独立对外
如果你还在初始化整个运行栈,请先阅读 用于部署的 SkillFlaw 安装说明 与 SkillFlaw 部署架构。
前置条件
- 目标机器上已经有一个运行中的 SkillFlaw 部署
- 一台支持 Nginx 的 Debian / Ubuntu 风格 Linux 主机
- 一个公网域名,且你有权修改 DNS 记录
- DNS 已经指向该服务器公网 IP
- 可通过系统包安装 Certbot
参考 compose 栈中的本地上游地址为:
| 服务 | 本地地址 | 用途 |
|---|---|---|
| Frontend | http://127.0.0.1:3001 | Web UI 和 /playground/:id/ 这类可共享 Playground 路由 |
| Backend | http://127.0.0.1:7860 | /health、/api/*、/api/v1/mcp/streamable、webhook 与 run 端点 |
| Docs | http://127.0.0.1:3002 | 可选的独立文档服务 |
选择公网路由模型
最清晰的生产方案是使用独立主机名:
app.example.com-> 前端api.example.com-> 后端docs.example.com-> 文档(可选)
这样可以把浏览器 UI、程序化 API 流量和文档访问彻底分开。
安装并启用 Nginx
-
安装 Nginx。
_10sudo apt update_10sudo apt install nginx -y -
启动并设置开机自启。
_10sudo systemctl enable --now nginx
为 SkillFlaw 配置 Nginx
下面的示例使用三个虚拟主机,不需要的可以删掉。
-
创建站点配置文件。
_10sudo nano /etc/nginx/sites-available/skillflaw.conf -
粘贴如下配置,并将示例域名替换为你的真实域名。
_53server {_53listen 80;_53server_name app.example.com;_53_53client_max_body_size 100M;_53_53location / {_53proxy_pass http://127.0.0.1:3001;_53proxy_http_version 1.1;_53proxy_set_header Host $host;_53proxy_set_header X-Real-IP $remote_addr;_53proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;_53proxy_set_header X-Forwarded-Proto $scheme;_53proxy_set_header Upgrade $http_upgrade;_53proxy_set_header Connection "upgrade";_53}_53}_53_53server {_53listen 80;_53server_name api.example.com;_53_53client_max_body_size 100M;_53_53location / {_53proxy_pass http://127.0.0.1:7860;_53proxy_http_version 1.1;_53proxy_set_header Host $host;_53proxy_set_header X-Real-IP $remote_addr;_53proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;_53proxy_set_header X-Forwarded-Proto $scheme;_53proxy_set_header Upgrade $http_upgrade;_53proxy_set_header Connection "upgrade";_53proxy_connect_timeout 60s;_53proxy_send_timeout 60s;_53proxy_read_timeout 300s;_53proxy_buffering off;_53proxy_request_buffering off;_53}_53}_53_53server {_53listen 80;_53server_name docs.example.com;_53_53location / {_53proxy_pass http://127.0.0.1:3002;_53proxy_set_header Host $host;_53proxy_set_header X-Real-IP $remote_addr;_53proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;_53proxy_set_header X-Forwarded-Proto $scheme;_53}_53} -
启用站点并校验配置语法。
_10sudo ln -sf /etc/nginx/sites-available/skillflaw.conf /etc/nginx/sites-enabled/skillflaw.conf_10sudo nginx -t -
重载 Nginx。
_10sudo systemctl reload nginx
使用 Certbot 申请 TLS 证书
-
安装 Certbot 与 Nginx 插件。
_10sudo apt install certbot python3-certbot-nginx -y -
为实际对外暴露的主机名申请证书。
_10sudo certbot --nginx -d app.example.com -d api.example.com -d docs.example.com如果你暴露的主机名更少,请删掉多余的
-d参数。 -
让 Certbot 自动更新 Nginx 配置,并按需选择是否将 HTTP 重定向到 HTTPS。
-
验证自动续期是否已启用。
_10systemctl list-timers | grep certbot
验证公网入口
TLS 启用后,按你的部署形态验证这些地址:
https://app.example.comhttps://api.example.com/healthhttps://api.example.com/api/v1/mcp/streamablehttps://docs.example.com
运维说明
SKILLFLAW_SECRET_KEY_FILE必须在后端运行环境中挂载为真实文件;Nginx 不会改变这个要求。SKILLFLAW_CONFIG_DIR应放在持久化存储上。- 如果你只暴露 API,可只对外开放后端域名,把前端与文档保留为私有或关闭。
- 如果你公开暴露 MCP,同样要使用与其他后端 API 一致的认证控制。