docs: 更新README部署文档
- 添加详细的生产环境部署指南 - 包含环境配置模板和部署步骤说明 - 添加PM2进程管理和部署架构图 - 说明环境变量配置和智能地址获取机制 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
78
README.md
78
README.md
@@ -132,6 +132,82 @@ simple_username
|
|||||||
|
|
||||||
## 🛠️ 部署
|
## 🛠️ 部署
|
||||||
|
|
||||||
推荐使用 [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) 部署 Next.js 应用。
|
### 生产环境部署
|
||||||
|
|
||||||
|
本系统支持灵活的部署方式,无需 nginx 即可在同一服务器上运行前后端服务。
|
||||||
|
|
||||||
|
#### 环境配置
|
||||||
|
|
||||||
|
1. **复制环境配置模板**
|
||||||
|
```bash
|
||||||
|
cp .env.template .env.production
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **编辑生产环境配置**
|
||||||
|
```bash
|
||||||
|
# .env.production
|
||||||
|
PORT=3000 # 前端服务端口
|
||||||
|
NEXT_PUBLIC_API_BASE_URL=http://服务器IP:3006 # 后端API地址(可选)
|
||||||
|
NODE_ENV=production
|
||||||
|
```
|
||||||
|
|
||||||
|
**注意**:
|
||||||
|
- 如果不设置 `NEXT_PUBLIC_API_BASE_URL`,系统会自动使用当前访问域名的 3006 端口
|
||||||
|
- 前后端部署在同一服务器时,可以不配置此项
|
||||||
|
|
||||||
|
#### 部署步骤
|
||||||
|
|
||||||
|
1. **构建项目**
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **启动生产服务器**
|
||||||
|
```bash
|
||||||
|
# 使用默认端口 3000
|
||||||
|
npm run start
|
||||||
|
|
||||||
|
# 或使用环境变量指定端口
|
||||||
|
PORT=8080 npm run start
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **使用 PM2 管理进程(推荐)**
|
||||||
|
```bash
|
||||||
|
# 安装 PM2
|
||||||
|
npm install -g pm2
|
||||||
|
|
||||||
|
# 启动应用
|
||||||
|
pm2 start npm --name "accounts-manager" -- run start
|
||||||
|
|
||||||
|
# 保存 PM2 配置
|
||||||
|
pm2 save
|
||||||
|
|
||||||
|
# 设置开机自启
|
||||||
|
pm2 startup
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 部署架构
|
||||||
|
|
||||||
|
```
|
||||||
|
服务器 (IP: xxx.xxx.xxx.xxx)
|
||||||
|
├── 前端服务: http://xxx.xxx.xxx.xxx:3000
|
||||||
|
└── 后端API: http://xxx.xxx.xxx.xxx:3006
|
||||||
|
```
|
||||||
|
|
||||||
|
用户访问 `http://服务器IP:3000` 即可使用完整功能。
|
||||||
|
|
||||||
|
#### 环境变量说明
|
||||||
|
|
||||||
|
| 变量名 | 说明 | 默认值 | 必填 |
|
||||||
|
|--------|------|--------|------|
|
||||||
|
| `PORT` | 前端服务端口 | 3000 | 否 |
|
||||||
|
| `NEXT_PUBLIC_API_BASE_URL` | 后端API地址 | 自动获取当前域名:3006 | 否 |
|
||||||
|
| `NODE_ENV` | 运行环境 | development | 否 |
|
||||||
|
|
||||||
|
#### 其他部署选项
|
||||||
|
|
||||||
|
- **Vercel**: 推荐用于前端静态部署 [部署链接](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
|
||||||
|
- **Docker**: 支持容器化部署
|
||||||
|
- **传统服务器**: 支持直接在服务器上运行
|
||||||
|
|
||||||
查看 [Next.js 部署文档](https://nextjs.org/docs/app/building-your-application/deploying) 了解更多部署选项。
|
查看 [Next.js 部署文档](https://nextjs.org/docs/app/building-your-application/deploying) 了解更多部署选项。
|
||||||
|
|||||||
Reference in New Issue
Block a user