fix: 更新域名从 lhgy.net 到 www.lhgy.net

- 更新 .env.local 中的域名配置
- 更新 infra/deploy/.env.local
- 更新 compose.local.yaml 中的环境变量
- 更新 admin-web 构建参数 VITE_API_BASE_URL
- 更新小程序 app.ts 中的 apiBaseUrl
This commit is contained in:
climber
2026-10-24 19:49:59 +08:00
parent a836d0c1be
commit 4412a416ed
16 changed files with 441 additions and 20 deletions
+92
View File
@@ -0,0 +1,92 @@
# 乐活公益平台 HTTPS 访问问题诊断报告
## 问题现象
- **本地访问正常**: `http://localhost:3000/api/v1/...` ✅
- **HTTPS访问失败**: `https://lhgy.net/api/v1/...` ❌
- **错误信息**: `"Cannot POST /v1/admin/auth/login"` (缺少 `/api/` 前缀)
- **影响范围**: 所有 `/api/v1/` 开头的API请求都被修改路径
## 根本原因
FRP服务器 (47.116.99.193) 上的 nginx 配置有问题。
**请求链路**:
```
客户端 → lhgy.net (443端口) → FRP服务器nginx → TCP隧道 → 本地nginx → API容器
```
**问题位置**: FRP服务器的nginx在转发请求时剥离了 `/api/` 前缀。
**验证**:
- 直接访问本地nginx: `curl -k https://127.0.0.1/api/v1/test` → ✅ 成功
- 通过域名访问: `curl -k https://lhgy.net/api/v1/test` → ❌ 路径变成 `/v1/test`
- 直接访问公网IP: `curl -k https://47.116.99.193/api/v1/test -H "Host: lhgy.net"` → ❌ 同样失败
## 需要检查的文件
在FRP服务器上执行以下命令检查nginx配置:
```bash
# 1. 查看所有nginx配置
sudo nginx -T | grep -A 20 "location /api"
# 2. 检查rewrite规则
sudo nginx -T | grep -i rewrite
# 3. 检查proxy_pass配置
sudo nginx -T | grep -B 5 -A 10 "proxy_pass"
# 4. 查看完整配置
sudo cat /etc/nginx/nginx.conf
sudo ls -la /etc/nginx/conf.d/
sudo ls -la /etc/nginx/sites-enabled/
```
## 修复方案
找到有问题的配置后,确保:
1. **`location /api/` 块的 proxy_pass 后面不要有路径**
```nginx
# 错误示例 (会修改路径):
location /api/ {
proxy_pass http://127.0.0.1:3000/; # 注意尾部斜杠
}
# 正确示例 (保留完整路径):
location /api/ {
proxy_pass http://127.0.0.1:3000; # 没有尾部斜杠
}
```
2. **不要有修改路径的 rewrite 规则**
```nginx
# 删除或注释掉类似这样的规则:
# rewrite ^/api/(.*)$ /$1 break;
```
3. **重载nginx**
```bash
sudo nginx -t && sudo nginx -s reload
```
## 临时绕过方案
如果无法立即修复FRP服务器,可以修改前端配置:
```bash
# 修改 .env.production
ADMIN_API_URL=https://lhgy.net:3000
# 或者使用FRP映射的其他端口
```
但这是临时方案,建议尽快修复FRP服务器的nginx配置。
## 验证方法
修复后测试:
```bash
curl -sk https://lhgy.net/api/v1/admin/auth/login \
-X POST \
-H "Content-Type: application/json" \
-H "Origin: https://lhgy.net" \
-d '{"username":"admin","password":"lehuo@123456"}'
```
期望返回包含 session 信息的JSON响应。