Files
test/new-api/docker-compose.yml
2026-11-05 14:10:48 +08:00

59 lines
2.2 KiB
YAML
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.
# ============================================================
# 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