Files
lotteryAdmin/ecosystem.config.cjs
2026-07-10 17:04:42 +08:00

51 lines
1.7 KiB
JavaScript
Raw 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.
/**
* 管理端lotteryadmin宝塔 PM2 配置
*
* 部署步骤(在服务器项目目录执行):
* 1. 本地 npm run build打包 .next/standalone + .next/static + public 上传服务器
* 2. 服务器:复制 .env.example 为 .env按线上域名填写
* 3. 修改下方 cwd 为服务器上的实际路径(默认即本文件所在目录)
* 4. pm2 start ecosystem.config.cjs
* 5. pm2 save && pm2 startup
*
* 宝塔PM2 管理器 → 添加项目 → 选择本文件。
* Nginx反代到 127.0.0.1:3801 即可;/api 由 Next 转发到 LOTTERY_API_UPSTREAM无需单独配。
*/
const path = require("path");
/** 改成服务器上的绝对路径,例如 /www/wwwroot/lottery-admin.cjdhr.top */
const DEPLOY_ROOT = path.resolve(__dirname);
// deploy.sh uploads the standalone bundle to app/. Keep runtime and static assets
// on the same build so Next.js chunk references cannot become mismatched.
const APP_CWD = path.join(DEPLOY_ROOT, "app");
module.exports = {
apps: [
{
name: "lotteryadmin",
cwd: APP_CWD,
script: "server.js",
interpreter: "node",
exec_mode: "fork",
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: "1G",
time: true,
merge_logs: true,
out_file: path.join(DEPLOY_ROOT, "logs/pm2-out.log"),
error_file: path.join(DEPLOY_ROOT, "logs/pm2-error.log"),
env: {
NODE_ENV: "production",
HOSTNAME: "0.0.0.0",
PORT: "3801",
},
// LOTTERY_API_UPSTREAM 只写在 .env勿在此硬编码会覆盖 .env 导致 API 502
env_file: path.join(DEPLOY_ROOT, ".env"),
},
],
};