feat: PM2 + Docker deployment config (MySQL container, PM2 for backend+frontend proxy)

This commit is contained in:
2026-07-06 10:12:05 +08:00
parent a568da160c
commit 2ce73b8fc3
7 changed files with 217 additions and 37 deletions

50
ecosystem.config.cjs Normal file
View File

@@ -0,0 +1,50 @@
// PM2 进程配置 — 恭学教育
// 用法: pm2 start ecosystem.config.cjs
// 前提: 项目部署在 /opt/gongxuedeploy.sh 默认路径)
// .env 文件在 /opt/gongxue/.env
// docker compose up -d 已启动 MySQL
const DEPLOY_DIR = process.env.DEPLOY_DIR || '/opt/gongxue';
module.exports = {
apps: [
{
name: 'gongxue-backend',
cwd: DEPLOY_DIR,
script: 'apps/server/dist/main.js',
// 集群模式2 实例,按 CPU 核数可调)
instances: 2,
exec_mode: 'cluster',
// 环境变量
env: {
NODE_ENV: 'production',
},
// 内存限制
max_memory_restart: '512M',
max_restarts: 10,
restart_delay: 5000,
// 日志
error_file: 'logs/backend-error.log',
out_file: 'logs/backend-out.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss',
autorestart: true,
watch: false,
},
{
name: 'gongxue-frontend',
cwd: DEPLOY_DIR,
script: 'serve-proxy.js',
env: {
NODE_ENV: 'production',
FRONTEND_PORT: 80, // 需 root 或 setcap: sudo setcap 'cap_net_bind_service=+ep' $(which node)
API_TARGET: 'http://127.0.0.1:3000',
},
max_memory_restart: '256M',
max_restarts: 5,
error_file: 'logs/frontend-error.log',
out_file: 'logs/frontend-out.log',
autorestart: true,
watch: false,
},
],
};