forked from wangziqi/gongxue-base
feat: PM2 + Docker deployment config (MySQL container, PM2 for backend+frontend proxy)
This commit is contained in:
50
ecosystem.config.cjs
Normal file
50
ecosystem.config.cjs
Normal file
@@ -0,0 +1,50 @@
|
||||
// PM2 进程配置 — 恭学教育
|
||||
// 用法: pm2 start ecosystem.config.cjs
|
||||
// 前提: 项目部署在 /opt/gongxue(deploy.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,
|
||||
},
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user