adjust order of content

This commit is contained in:
david_bai
2025-06-26 21:18:48 +08:00
parent 06e8185a06
commit 1646885454
2 changed files with 94 additions and 94 deletions
+48 -48
View File
@@ -152,59 +152,16 @@ cd backend && npm install && cd ..
cd frontend && pnpm install && cd ..
```
### 4.2. Configure Environment Variables
- **Backend:**
- Create a `.env.production.local` file in the `backend/` directory.
- Fill in the necessary environment variables (e.g., `PORT`, `REDIS_HOST`, `REDIS_PORT`, `CORS_ORIGIN`).
- For Nginx integration, also add `NGINX_SERVER_NAME`, `NGINX_SSL_CERT`, `NGINX_SSL_KEY`, and `NGINX_FRONTEND_ROOT`.
- **Frontend:**
- Create a `.env.production.local` file in the `frontend/` directory.
- Fill in the `NEXT_PUBLIC_API_URL` variable.
### 4.3. Build the Frontend Application
### 4.2. Build the Frontend Application
```bash
cd frontend
pnpm build
cd frontend && pnpm build && cd ..
cd backend && npm build && cd ..
```
This will generate an optimized production build in the `frontend/.next` directory.
This will generate an optimized production build in the `frontend/.next` and `backend/dist` directory.
### 4.4. Run the Application with PM2
PM2 is a powerful process manager for Node.js. We will use it to run the backend and frontend services separately.
1. **Install PM2 globally:**
```bash
sudo npm install -g pm2
```
2. **Start the Backend Service:**
The backend directory provides an `ecosystem.config.js` file for PM2.
```bash
cd backend
# Ensure .env.production.local is fully configured
pm2 start ecosystem.config.js
```
3. **Start the Frontend Service:**
```bash
cd frontend
pm2 start npm --name "privydrop-frontend" -- run start
```
The `npm start` command starts the Next.js production server, which listens on port 3000 by default.
4. **Manage Applications:**
- View status: `pm2 list`
- View logs: `pm2 logs <app_name>`
- Set up startup script: `pm2 startup` followed by `pm2 save`
### 4.5. Configure Nginx as a Reverse Proxy
### 4.3. Configure Nginx as a Reverse Proxy
In production, Nginx will act as the entry point for all traffic, handling SSL termination and routing requests to the correct frontend or backend service.
@@ -237,6 +194,49 @@ In production, Nginx will act as the entry point for all traffic, handling SSL t
sudo bash backend/docker/Nginx/configure.sh backend/.env.production.local
```
### 4.4. Configure Environment Variables
- **Backend:**
- Create a `.env.production.local` file in the `backend/` directory.
- Fill in the necessary environment variables (e.g., `PORT`, `REDIS_HOST`, `REDIS_PORT`, `CORS_ORIGIN`).
- For Nginx integration, also add `NGINX_SERVER_NAME`, `NGINX_SSL_CERT`, `NGINX_SSL_KEY`, and `NGINX_FRONTEND_ROOT`.
- **Frontend:**
- Create a `.env.production.local` file in the `frontend/` directory.
- Fill in the `NEXT_PUBLIC_API_URL` variable.
### 4.5. Run the Application with PM2
PM2 is a powerful process manager for Node.js. We will use it to run the backend and frontend services separately.
1. **Install PM2 globally:**
```bash
sudo npm install -g pm2
```
2. **Start the Backend Service:**
The backend directory provides an `ecosystem.config.js` file for PM2.
```bash
cd backend
# Ensure .env.production.local is fully configured
pm2 start ecosystem.config.js
```
3. **Start the Frontend Service:**
```bash
cd frontend
pm2 start npm --name "privydrop-frontend" -- run start
```
The `npm start` command starts the Next.js production server, which listens on port 3000 by default.
4. **Manage Applications:**
- View status: `pm2 list`
- View logs: `pm2 logs <app_name>`
- Set up startup script: `pm2 startup` followed by `pm2 save`
## 5. Troubleshooting
- **Connection Issues:** Check firewall settings, Nginx proxy configurations, `CORS_ORIGIN` settings, and ensure all PM2 processes are running.
+46 -46
View File
@@ -152,57 +152,16 @@ cd backend && npm install && cd ..
cd frontend && pnpm install && cd ..
```
### 4.2. 配置环境变量
- **后端:**
- 在 `backend/` 目录下创建 `.env.production.local` 或 `.env.development.local` 文件
- 在 `.env.development.local` 文件中填入环境变量 (BACKEND_PORT, REDIS_HOST, REDIS_PORT, CORS_ORIGIN)。
- 在 `.env.production.local` 文件中除了上述变量外,还要加入 (NGINX_SERVER_NAME, NGINX_SSL_CERT, NGINX_SSL_KEY, NGINX_FRONTEND_ROOT)。
- **前端:** 在 `frontend/` 目录下创建 `.env.production` 或 `.env.development` 文件,并填入环境变量 (NEXT_PUBLIC_API_URL)。
### 4.3. 构建前端应用
### 4.2. 构建应用
```bash
cd frontend
pnpm build
cd frontend && pnpm build && cd ..
cd backend && npm build && cd ..
```
这将在 `frontend/.next` 目录生成优化后的生产版本。
这将分别在 `frontend/.next` 和 `backend/dist` 目录生成优化后的生产版本。
### 4.4. 使用 PM2 运行应用
PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行后端服务和前端服务。
1. **全局安装 PM2**
```bash
sudo npm install -g pm2
```
2. **启动后端服务:**
项目后端目录提供了一个 `ecosystem.config.js` 文件用于 PM2。
```bash
cd backend
# 确保 .env.production.local 已配置完毕
pm2 start ecosystem.config.js
```
3. **启动前端服务:**
```bash
cd frontend
pm2 start npm --name "privydrop-frontend" -- run start
```
`npm start` 会启动 Next.js 的生产服务器,默认监听 3000 端口。
4. **管理应用**
- 查看状态: `pm2 list`
- 查看日志: `pm2 logs <app_name>`
- 设置开机自启: `pm2 startup` 然后 `pm2 save`
### 4.5. 配置 Nginx 作为反向代理
### 4.3. 配置 Nginx 作为反向代理
在生产中,Nginx 将作为所有流量的入口,负责 SSL 终止,并将请求路由到正确的前端或后端服务。
@@ -235,6 +194,47 @@ PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行
sudo bash docker/Nginx/configure.sh .env.production.local
```
### 4.4. 配置环境变量
- **后端:**
- 在 `backend/` 目录下创建 `.env.production.local` 或 `.env.development.local` 文件
- 在 `.env.development.local` 文件中填入环境变量 (BACKEND_PORT, REDIS_HOST, REDIS_PORT, CORS_ORIGIN)。
- 在 `.env.production.local` 文件中除了上述变量外,还要加入 (NGINX_SERVER_NAME, NGINX_SSL_CERT, NGINX_SSL_KEY, NGINX_FRONTEND_ROOT)。
- **前端:** 在 `frontend/` 目录下创建 `.env.production` 或 `.env.development` 文件,并填入环境变量 (NEXT_PUBLIC_API_URL)。
### 4.5. 使用 PM2 运行应用
PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行后端服务和前端服务。
1. **全局安装 PM2**
```bash
sudo npm install -g pm2
```
2. **启动后端服务:**
项目后端目录提供了一个 `ecosystem.config.js` 文件用于 PM2。
```bash
cd backend
# 确保 .env.production.local 已配置完毕
pm2 start ecosystem.config.js
```
3. **启动前端服务:**
```bash
cd frontend
pm2 start npm --name "privydrop-frontend" -- run start
```
`npm start` 会启动 Next.js 的生产服务器,默认监听 3000 端口。
4. **管理应用**
- 查看状态: `pm2 list`
- 查看日志: `pm2 logs <app_name>`
- 设置开机自启: `pm2 startup` 然后 `pm2 save`
## 5. 故障排除
- **连接问题:** 检查防火墙、Nginx 代理设置、CORS_ORIGIN 配置,确保所有 PM2 进程都在运行。