diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 9244d1f..a3d70a6 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -2,8 +2,8 @@ * 管理端(lotteryadmin)宝塔 PM2 配置 * * 部署步骤(在服务器项目目录执行): - * 1. 复制 .env.example 为 .env,按线上域名填写 - * 2. npm ci && npm run build + * 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 @@ -22,8 +22,7 @@ module.exports = { { name: "lotteryadmin", cwd: APP_CWD, - script: "node_modules/next/dist/bin/next", - args: "start -p 3801 -H 127.0.0.1", + script: ".next/standalone/server.js", interpreter: "node", exec_mode: "fork", instances: 1, @@ -37,6 +36,7 @@ module.exports = { env: { NODE_ENV: "production", + HOSTNAME: "0.0.0.0", PORT: "3801", }, diff --git a/next.config.ts b/next.config.ts index ca96a55..35abba7 100644 --- a/next.config.ts +++ b/next.config.ts @@ -5,9 +5,12 @@ import { parseAllowedDevOrigins } from "./src/lib/next-dev-origins"; const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS); const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", ...(allowedDevOrigins.length > 0 ? { allowedDevOrigins } : {}), reactCompiler: true, + images: { + unoptimized: true, + }, async redirects() { return [ { diff --git a/package.json b/package.json index b8f67c7..38ec957 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "NEXT_DISABLE_MEM_OVERRIDE=1 NODE_OPTIONS='--max-old-space-size=3072' next dev --port 3801", - "build": "next build", + "build": "next build && cp -r .next/static .next/standalone/.next/static && cp -r public .next/standalone/public && echo '✅ standalone 静态资源已复制完毕'", "start": "next start --port 3801", "lint": "eslint" }, diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..7bbf354 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# lotteryadmin 一键部署脚本 +# 用法: bash scripts/deploy.sh + +set -e + +SERVER="root@47.242.205.221" +REMOTE_DIR="/www/wwwroot/lotteryAdmin" + +echo "🔨 构建中..." +npm run build + +echo "📦 上传到服务器..." +ssh ${SERVER} "mkdir -p ${REMOTE_DIR}/.next/standalone ${REMOTE_DIR}/logs" +rsync -avz --delete .next/standalone/ ${SERVER}:${REMOTE_DIR}/.next/standalone/ +rsync -avz ecosystem.config.cjs ${SERVER}:${REMOTE_DIR}/ecosystem.config.cjs + +echo "🚀 服务器重启 PM2..." +ssh ${SERVER} "source /etc/profile && source ~/.bashrc && mkdir -p ${REMOTE_DIR}/logs && cd ${REMOTE_DIR} && (pm2 restart lotteryadmin 2>/dev/null || pm2 start ecosystem.config.cjs) && pm2 save" + +echo "✅ lotteryAdmin 部署完成!"