docs: 添加后端检查和网络问题诊断报告
This commit is contained in:
169
NETWORK_ERROR_DIAGNOSIS.md
Normal file
169
NETWORK_ERROR_DIAGNOSIS.md
Normal file
@@ -0,0 +1,169 @@
|
||||
# 网络连接失败问题诊断
|
||||
|
||||
**诊断时间**: 2026-03-23 23:41
|
||||
**问题**: 前端报"网络连接失败"
|
||||
|
||||
---
|
||||
|
||||
## 🔍 **问题根源**
|
||||
|
||||
### **前端配置**
|
||||
|
||||
**文件**: `flutter_monisuo/lib/core/constants/api_endpoints.dart`
|
||||
|
||||
```dart
|
||||
static const String _env = String.fromEnvironment('ENV', defaultValue: 'dev');
|
||||
|
||||
static const String baseUrl = _env == 'prod'
|
||||
? 'http://8.155.172.147:5010'
|
||||
: 'http://localhost:5010';
|
||||
```
|
||||
|
||||
**配置分析**:
|
||||
- **开发环境** (默认): `http://localhost:5010`
|
||||
- **生产环境** (ENV=prod): `http://8.155.172.147:5010`
|
||||
|
||||
---
|
||||
|
||||
## 📊 **当前状态**
|
||||
|
||||
### **本地后端服务** ✅
|
||||
- **地址**: `http://localhost:5010`
|
||||
- **状态**: ✅ 正常运行
|
||||
- **测试**: ✅ API 接口正常响应
|
||||
|
||||
### **远程后端服务** ❓
|
||||
- **地址**: `http://8.155.172.147:5010`
|
||||
- **状态**: ❓ 未知(需要检查)
|
||||
|
||||
---
|
||||
|
||||
## 🔧 **解决方案**
|
||||
|
||||
### **方案 1: 检查远程服务器后端**
|
||||
|
||||
在远程服务器上执行:
|
||||
|
||||
```bash
|
||||
ssh root@8.155.172.147
|
||||
|
||||
# 检查后端服务是否运行
|
||||
ps aux | grep monisuo-1.0.jar
|
||||
|
||||
# 检查端口是否监听
|
||||
netstat -tunlp | grep 5010
|
||||
|
||||
# 查看服务日志
|
||||
tail -f /var/log/monisuo/app.log
|
||||
|
||||
# 如果服务未运行,启动服务
|
||||
cd /path/to/monisuo
|
||||
git pull origin main
|
||||
systemctl restart monisuo
|
||||
# 或
|
||||
nohup java -jar target/monisuo-1.0.jar --server.port=5010 > /var/log/monisuo/app.log 2>&1 &
|
||||
```
|
||||
|
||||
### **方案 2: 使用本地后端(开发环境)**
|
||||
|
||||
如果前端是在本地运行(开发环境):
|
||||
|
||||
1. **确保后端服务在本地运行**
|
||||
```bash
|
||||
cd ~/Desktop/projects/monisuo
|
||||
java -jar target/monisuo-1.0.jar --server.port=5010
|
||||
```
|
||||
|
||||
2. **前端连接本地后端**
|
||||
- 前端默认配置是 `http://localhost:5010`
|
||||
- 无需修改配置
|
||||
|
||||
### **方案 3: 检查网络连接**
|
||||
|
||||
**在浏览器中测试**:
|
||||
1. 打开浏览器
|
||||
2. 访问 `http://localhost:5010/api/wallet/default`
|
||||
3. 查看是否能正常访问
|
||||
|
||||
**如果无法访问**:
|
||||
- 检查防火墙设置
|
||||
- 检查浏览器安全策略
|
||||
- 检查 CORS 配置
|
||||
|
||||
---
|
||||
|
||||
## 🎯 **推荐操作**
|
||||
|
||||
### **立即检查远程服务器**
|
||||
|
||||
```bash
|
||||
# 1. SSH 登录服务器
|
||||
ssh root@8.155.172.147
|
||||
|
||||
# 2. 检查服务状态
|
||||
systemctl status monisuo
|
||||
|
||||
# 3. 如果服务未运行,启动服务
|
||||
cd /path/to/monisuo
|
||||
git pull origin main
|
||||
systemctl restart monisuo
|
||||
|
||||
# 4. 查看启动日志
|
||||
journalctl -u monisuo -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 **检查清单**
|
||||
|
||||
- [ ] 检查远程服务器后端是否运行
|
||||
- [ ] 检查远程服务器端口 5010 是否开放
|
||||
- [ ] 检查防火墙规则
|
||||
- [ ] 检查前端环境变量配置
|
||||
- [ ] 测试后端 API 接口
|
||||
- [ ] 查看后端日志
|
||||
|
||||
---
|
||||
|
||||
## 🚨 **常见问题**
|
||||
|
||||
### **问题 1: 端口未开放**
|
||||
|
||||
**症状**: 无法连接到远程服务器
|
||||
|
||||
**解决**:
|
||||
```bash
|
||||
# 开放端口 5010
|
||||
firewall-cmd --add-port=5010/tcp --permanent
|
||||
firewall-cmd --reload
|
||||
```
|
||||
|
||||
### **问题 2: 服务未启动**
|
||||
|
||||
**症状**: 端口未监听
|
||||
|
||||
**解决**:
|
||||
```bash
|
||||
systemctl restart monisuo
|
||||
```
|
||||
|
||||
### **问题 3: CORS 问题**
|
||||
|
||||
**症状**: 浏览器控制台报 CORS 错误
|
||||
|
||||
**解决**: 后端已配置 CORS,应该不会有此问题
|
||||
|
||||
---
|
||||
|
||||
## ✅ **总结**
|
||||
|
||||
**后端服务**: ✅ 本地正常
|
||||
**前端配置**: ✅ 正确
|
||||
**问题**: ⚠️ 远程服务器后端可能未运行
|
||||
|
||||
**下一步**: 检查远程服务器后端服务状态
|
||||
|
||||
---
|
||||
|
||||
**诊断完成时间**: 2026-03-23 23:41
|
||||
**建议**: 优先检查远程服务器后端是否运行
|
||||
Reference in New Issue
Block a user