xinli/项目介绍/环境配置/3. 前后端以及App访问地址.md
2026-01-30 16:23:00 +08:00

161 lines
5.5 KiB
Markdown
Raw Permalink 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.

# 前后端及App访问地址配置
## 环境地址汇总
| 环境 | IP地址 | 说明 |
|------|--------|------|
| **本机开发** | 192.168.1.164 | 本地开发调试 |
| **内网部署** | 192.168.0.106 | 服务器部署环境 |
## 需要修改的文件
### 1. App端Android
| 文件路径 | 配置项 | 说明 |
|----------|--------|------|
| `xinli-App/app/src/main/java/com/xinli/app/MainActivity.java` | `FIXED_URL` | App访问的前端地址 |
**内网部署环境(当前):**
```java
private static final String FIXED_URL = "http://192.168.0.106:80?app=1";
```
**切换回本机开发:**
```java
private static final String FIXED_URL = "http://192.168.1.164:80?app=1";
```
### 2. 前端Vue
| 文件路径 | 配置项 | 说明 |
|----------|--------|------|
| `xinli-ui/vue.config.js` | `baseUrl` | 开发环境后端地址 |
| `xinli-ui/.env.production` | `VUE_APP_BASE_API` | 生产环境API前缀 |
**vue.config.js 当前配置:**
```javascript
const baseUrl = process.env.NODE_ENV === 'development'
? 'http://localhost:30081' // 本地开发环境
: '/api' // 生产环境通过nginx代理
```
**生产环境说明:**
- 生产环境使用 `/api` 前缀由nginx代理到后端
- 不需要修改前端代码只需配置nginx
### 3. 后端Java
| 文件路径 | 配置项 | 说明 |
|----------|--------|------|
| `ry-xinli-admin/src/main/resources/application.yml` | `server.port` | 后端服务端口 |
**当前配置:**
```yaml
server:
port: 30081
```
## 部署架构
```
┌─────────────────────────────────────────────────────────────┐
│ 内网环境 (192.168.0.106) │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Nginx │ │ Java后端 │ │ Python RAG │ │
│ │ :80 │───▶│ :30081 │───▶│ :5000 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │ │
│ │ │ ▼ │
│ │ │ ┌─────────────┐ │
│ │ │ │ Ollama │ │
│ │ │ │ :11434 │ │
│ │ │ └─────────────┘ │
│ ▼ │ │
│ ┌─────────────┐ │ │
│ │ 前端静态 │ │ │
│ │ 文件 │ │ │
│ └─────────────┘ │ │
│ │ │
└───────────────────────────┼───────────────────────────────┘
┌─────────────┐
│ Android │
│ App │
│ 访问:80 │
└─────────────┘
```
## Nginx配置示例
```nginx
server {
listen 80;
server_name 192.168.0.106;
# 前端静态文件
location / {
root /www/wwwroot/xinli/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
# 后端API代理
location /api/ {
proxy_pass http://127.0.0.1:30081/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# RAG服务代理如需外部访问
location /rag/ {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
}
}
```
## 服务端口汇总
| 服务 | 端口 | 说明 |
|------|------|------|
| Nginx | 80 | 前端入口App访问此端口 |
| Java后端 | 30081 | 后端API服务 |
| Python RAG | 5000 | 知识库检索服务 |
| Ollama | 11434 | 大模型服务 |
| MySQL | 3306 | 数据库远程1.15.149.240 |
| Redis | 6379 | 缓存服务 |
## 切换到内网部署的步骤
1. **修改App地址**(如需要):
```java
// xinli-App/app/src/main/java/com/xinli/app/MainActivity.java
private static final String FIXED_URL = "http://192.168.0.106:80?app=1";
```
2. **重新打包App**
```bash
cd xinli-App
./gradlew assembleRelease
```
3. **前端打包**(不需要修改代码):
```bash
cd xinli-ui
npm run build:prod
```
4. **配置Nginx**将上述nginx配置应用到服务器
5. **启动服务**
```bash
# 1. 启动Ollama
ollama serve
# 2. 启动Python RAG
cd rag-python && python app.py
# 3. 启动Java后端
java -jar xinli-admin.jar
```