落叶楼阅读app最新版本
27.23MB · 2025-12-15
假设你的 Next.js 项目目录如下:
package.json
package-lock.json / yarn.lock
pages/
public/
components/
next.config.js
node_modules/
如果使用 npm:
npm install
如果使用 yarn:
yarn install
Next.js 提供 next build 命令生成生产构建产物:
npm run build
# 或者
yarn build
.next/ 目录,包含 SSR 所需文件next start 启动生产服务npm start
# 或者
yarn start
3000生产部署至少需要以下内容:
package.json
package-lock.json / yarn.lock
.next/ # SSR 构建产物
public/ # 静态资源
node_modules/ # 可上传,也可服务器安装
zip -r next-prod.zip package.json package-lock.json .next public .env
scp 上传scp next-prod.zip user@yourserver:/path/to/app
ssh user@yourserver
unzip next-prod.zip -d next-app
cd next-app
npm install --production
# 或者
yarn install --production
Next.js SSR 项目常用环境变量:
NODE_ENV=production
PORT=3000
NEXT_PUBLIC_API_URL=
npm start
# 或者
yarn start
http://你的域名或公网IP:3000npm install -g pm2
pm2 start npm --name "next-app" -- start
pm2 save
pm2 startup
Dockerfile 示例:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
RUN npm run build
CMD ["npm", "start"]
EXPOSE 3000
构建 & 运行:
docker build -t next-app .
docker run -d -p 3000:3000 next-app
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass ;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
npm install / yarn installnpm run build / yarn build 生成 .next/.next/ + public/ + package.json + node_modules(可选)npm start / PM2 / Docker 启动PORT 与之匹配通过以上步骤,你可以快速将 Next.js SSR 项目 打包、上传,并在 1Panel 或 VPS 上运行生产环境,实现服务端渲染。