first commit
This commit is contained in:
commit
47218488aa
10 files changed
+1438
No files matched your search
@@ -0,0 +1,58 @@
|
||||
# ============================================================
|
||||
# New API —— 腾讯云新加坡轻量服务器 · 同机部署版(SQLite 单容器)
|
||||
#
|
||||
# 服务器:43.156.118.130 / Ubuntu 24.04 LTS / 2核2G / 40G
|
||||
# 共存服务:Xray + Shadowsocks(端口 8388,互不干扰,勿动)
|
||||
#
|
||||
# 部署目录:/opt/new-api
|
||||
# /opt/new-api/docker-compose.yml ← 本文件
|
||||
# /opt/new-api/.env ← 存放 SESSION_SECRET(权限 600)
|
||||
# /opt/new-api/data/ ← SQLite 数据库 + 上传文件
|
||||
# /opt/new-api/logs/ ← 应用日志
|
||||
#
|
||||
# 启动:docker compose up -d
|
||||
# 日志:docker compose logs -f new-api
|
||||
# ============================================================
|
||||
|
||||
services:
|
||||
new-api:
|
||||
image: calciumion/new-api:latest
|
||||
container_name: new-api
|
||||
restart: unless-stopped
|
||||
command: --log-dir /app/logs
|
||||
|
||||
# 只绑回环地址:外部只能经 Nginx(443) 访问,
|
||||
# 无法绕过 HTTPS 直连 3000 端口(Docker 会绕过 ufw,这一点很关键)
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
|
||||
volumes:
|
||||
- ./data:/data
|
||||
- ./logs:/app/logs
|
||||
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- ERROR_LOG_ENABLED=true
|
||||
- BATCH_UPDATE_ENABLED=true
|
||||
- NODE_NAME=new-api-sg-1
|
||||
- STREAMING_TIMEOUT=300
|
||||
|
||||
# ---------- 会话与安全 ----------
|
||||
# SESSION_SECRET 从同目录 .env 读取,值由 `openssl rand -hex 32` 生成。
|
||||
# 缺失时 Compose 会直接报错停下,不会用空密钥静默启动。
|
||||
- "SESSION_SECRET=${SESSION_SECRET:?未设置 SESSION_SECRET,请检查 /opt/new-api/.env}"
|
||||
- SESSION_COOKIE_SECURE=true # 必须 true,配合 HTTPS
|
||||
- SESSION_COOKIE_TRUSTED_URL=https://api.trivoo.online
|
||||
|
||||
# Nginx 跑在宿主机,容器看到的是 Docker 网桥网关地址
|
||||
- TRUSTED_PROXIES=127.0.0.1,172.17.0.0/16
|
||||
|
||||
# 保护梯子:给容器设内存上限,防止 New API 吃光 2GB 把 Xray 一起拖垮
|
||||
mem_limit: 800m
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", 'wget -qO- http://localhost:3000/api/status | grep -qE "success[[:space:]]*:[[:space:]]*true" || exit 1']
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
@@ -0,0 +1,51 @@
|
||||
# ============================================================
|
||||
# Nginx 站点配置 —— api.trivoo.online 反向代理到 New API
|
||||
#
|
||||
# 目标路径:/etc/nginx/sites-available/api.trivoo.online
|
||||
# 启用:ln -s /etc/nginx/sites-available/api.trivoo.online \
|
||||
# /etc/nginx/sites-enabled/
|
||||
# nginx -t && systemctl reload nginx
|
||||
#
|
||||
# 先以 HTTP 建站跑通,再执行 sudo certbot --nginx
|
||||
# certbot 会自动把本文件改写成含 443 + 跳转的版本
|
||||
# ============================================================
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name api.trivoo.online;
|
||||
|
||||
# 音频转录 / 图片编辑等大文件上传(Nginx 默认仅 1m,会 413)
|
||||
client_max_body_size 100m;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
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;
|
||||
|
||||
# WebSocket —— /v1/realtime 与 /v1/responses 需要
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
|
||||
# 流式响应(SSE)必须关闭缓冲,否则会被攒着一次性吐出
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_request_buffering off;
|
||||
|
||||
# 非流式请求要等上游生成完才返回响应头,超时给足
|
||||
proxy_read_timeout 1800s;
|
||||
proxy_send_timeout 1800s;
|
||||
send_timeout 1800s;
|
||||
|
||||
chunked_transfer_encoding on;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user