Files

224 lines
9.6 KiB
Nginx Configuration File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
server {
listen 80;
server_name _;
# 本端口(host 3006)供 NPS 隧道(cut.88531.cn)以「明文 HTTP」接入:
# NPS 在服务端终结 TLS 后向目标转发明文,故这里绝不能再 301 跳 https
# (否则隧道侧无限重定向)。改为内部回环代理到本容器的 443,
# 复用下面 443 server 块的全部站点/AI/CDN 反代逻辑,无需重复配置。
# 浏览器侧地址仍是 https://cut.88531.cn(由 NPS 服务端提供 TLS),
# 因此 File System Access API 的「安全上下文」要求依然满足。
location / {
proxy_pass https://127.0.0.1:443;
proxy_ssl_server_name on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
client_max_body_size 2048m;
}
}
server {
listen 443 ssl;
http2 on;
server_name _;
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_types text/plain text/css application/json application/javascript image/svg+xml;
# SPA 路由回退
location / {
try_files $uri $uri/ /index.html;
}
# 文章目录禁止启发式缓存:index.json 更新(新增文章/改标题)后必须立即可见,
# 否则浏览器按 ETag/Last-Modified 自行推断新鲜度会命中旧列表 → 详情页报
# 「没有找到这篇文章」。no-cache = 每次协商校验(命中 304,不费流量)。
location /articles/ {
add_header Cache-Control "no-cache";
}
# 入口页同样不缓存:旧 index.html 会引用已不存在的旧 chunk hash
location = /index.html {
add_header Cache-Control "no-cache";
}
# 长缓存带 hash 的构建产物
location /homeAssets/ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# 公网部署不内置 AI 通道:/civideo、/omniai 反代已移除(AI 生图/生视频改由
# 用户在「AI 设置」填自己的网关地址直连,服务端不再注入任何模型密钥)。
# 官方素材 CDN(模板工程 JSON、模板缩略图)同源反代:
# 浏览器只请求 https://<站点>/cdn/**,不再直连 cdn.h5ds.com;
# 断网时该目录自然取不到(模板面板本就是联网能力),本机模板 /templates/** 不受影响。
location /cdn/ {
proxy_pass https://cdn.h5ds.com/;
proxy_ssl_server_name on;
proxy_set_header Host cdn.h5ds.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300s;
client_max_body_size 2048m;
}
# 兜底:官方素材的同源相对路径(/video/… 与 /video_business/…)直接转发到 CDN。
#
# 为什么需要它 —— 模板列表接口返回的是相对路径,正常应由前端改写到 /cdn/;
# 一旦改写逻辑丢失或被人改坏,这些路径会落到下面的 try_files 兜底,
# 返回 200 text/html 的 SPA 首页,<img> 拿到 HTML 当然裂图,而且「200 + 裂图」
# 极难排查(看着不像出错)。在这里直接转发到 CDN,既修好这一类问题,
# 也让返回内容始终保持为真实图片。
location ~ ^/(video|video_business)/ {
proxy_pass https://cdn.h5ds.com/$uri;
proxy_ssl_server_name on;
proxy_set_header Host cdn.h5ds.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300s;
client_max_body_size 2048m;
}
# 授权中心(CardAuth,auth.88531.cn)同源反代:安装统计 / 在线人数 / 公告 / 版本推送。
# 项目密钥 X-Api-Key 由 entrypoint.sh 在容器启动时注入,前端包与浏览器都不出现;
# 前端只请求同源 /hub/**,因此不存在跨域、也无需 CORS。密钥缺失时接口会失败,
# 前端按「无数据」安静降级(不弹错、不影响剪辑)。
location /hub/ {
proxy_pass https://auth.88531.cn/api/public/;
proxy_ssl_server_name on;
proxy_http_version 1.1;
proxy_set_header Host auth.88531.cn;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Api-Key "__HUB_KEY__";
proxy_read_timeout 30s;
proxy_send_timeout 30s;
client_max_body_size 1m;
}
# 网址抓取(AI 一键出片「输入网址」):同源动态反代任意公网 URL。
# 浏览器只请求 /grab/,避开跨域限制;只放行 http/https,
# 并拒绝回环/内网/链路本地地址,防止被当成跳板打内网服务。
# 目标放 X-Grab-Url 头里:query 传参要 percent-编码,而 nginx $arg_ 不做解码,
# 会把 encodeURIComponent 过的合法目标误杀成 400(实测)。3xx 原样透传给前端,
# 由 redirect:manual 逐跳重进 /grab/(每跳重新过一遍下面的断言)。
location = /grab/ {
resolver 223.5.5.5 119.29.29.29 valid=30s ipv6=off;
if ($http_x_grab_url = '') { return 400; }
if ($http_x_grab_url !~* '^https?://') { return 400; }
if ($http_x_grab_url ~* '^https?://[^/?#]*@') { return 403; }
if ($http_x_grab_url ~* '^https?://(localhost|127\.|0\.0\.0\.0|10\.|192\.168\.|169\.254\.|172\.(1[6-9]|2[0-9]|3[01])\.|\[?::1)') { return 403; }
proxy_pass $http_x_grab_url;
proxy_ssl_server_name on;
proxy_set_header Host $proxy_host;
proxy_set_header Connection "";
proxy_set_header X-Grab-Url "";
# 公众号图片防盗链:带异源 Referer 时 mmbiz.qpic.cn 只给降级缩略图
# (实测 2KB/140x140,无 Referer 则 47KB/原尺寸),向上游清空该头
proxy_set_header Referer "";
proxy_http_version 1.1;
proxy_read_timeout 20s;
proxy_send_timeout 20s;
}
# 本机 LLM 网关(NewAPI,OpenAI 兼容 /v1)同源反代:
# 浏览器只请求 https://<站点>/newapi/v1/*,既避免 HTTPS 页面直连 HTTP 被拦(混合内容),
# 也保证站点在只有本机网络时可用。密钥仍留在服务端,前端不出现。
location /newapi/ {
proxy_pass http://192.168.68.19:3099/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
client_max_body_size 20m;
}
# 本机语音合成服务(unicut-tts 容器),同源反代,避免 HTTPS 页面加载 HTTP 音频被拦
location /localtts/ {
proxy_pass http://unicut-tts:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 180s;
client_max_body_size 8m;
}
# MCP 服务(Model Context Protocol,unicut-mcp 容器)同源反代:
# AI 客户端(Claude Desktop / Claude Code / Cursor / Hermes 等)用
# https://<站点>/mcp
# 连接即可把米剪当工具用(抓取文章 / 生成口播文案 / edge-tts 配音 / 生成工程 ZIP)。
# Streamable HTTP 走 SSE 流:必须关缓冲、保持 HTTP/1.1 长连接、拉长读超时。
# 注:/mcp-out 前缀比 /mcp 更长,nginx 最长前缀匹配规则会优先后者,不冲突。
location /mcp {
proxy_pass http://unicut-mcp:8765;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "";
proxy_buffering off;
proxy_request_buffering off;
proxy_cache off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
client_max_body_size 20m;
}
# MCP 生成产物下载(工程 ZIP、配音 mp3),配合米剪「工程文件」导入
location /mcp-out/ {
proxy_pass http://unicut-mcp:8765/out/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 300s;
client_max_body_size 100m;
}
# MCP 健康检查(容器 /health;注意 /mcp/health 不是端点,SPA 会回退成首页 HTML)
location = /mcp-health {
proxy_pass http://unicut-mcp:8765/health;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_read_timeout 10s;
}
# UNICUT 在线服务反代(账号/素材/AI 等在线能力), 对应官方 dev server 的代理配置
location /api/ {
proxy_pass https://video.h5ds.com;
proxy_ssl_server_name on;
proxy_set_header Host video.h5ds.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 300s;
client_max_body_size 2048m;
}
location /cgi-bin/ {
proxy_pass https://video.h5ds.com;
proxy_ssl_server_name on;
proxy_set_header Host video.h5ds.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 300s;
client_max_body_size 2048m;
}
}