wecom-dashboards/deploy/PORT-CONFIG.md

182 lines
3.1 KiB
Markdown
Raw Normal View History

2026-02-08 08:22:43 +00:00
# 端口配置说明
## 当前端口配置
### 后端服务
- **容器内端口**: 8888
- **宿主机端口**: 8888
- **访问地址**: `http://your-server-ip:8888`
### 前端服务
- **容器内端口**: 80
- **宿主机端口**: 8889
- **访问地址**: `http://your-server-ip:8889/ashai-wecom-test`
## 配置文件位置
### 1. 后端端口配置
**文件**: [backend/application-druid.yml](backend/application-druid.yml)
```yaml
server:
port: 8888
```
### 2. Docker 端口映射
**文件**: [docker-compose.yml](docker-compose.yml)
```yaml
services:
backend:
ports:
- "8888:8888" # 宿主机:容器
frontend:
ports:
- "8889:80" # 宿主机:容器
```
### 3. Dockerfile 暴露端口
**文件**: [backend/Dockerfile](backend/Dockerfile)
```dockerfile
EXPOSE 8888
```
## 修改端口
如果需要修改端口,需要同时修改以上三个地方:
### 示例:改为 9000 端口
1. **修改 application-druid.yml**:
```yaml
server:
port: 9000
```
2. **修改 docker-compose.yml**:
```yaml
ports:
- "9000:9000"
```
3. **修改 Dockerfile**:
```dockerfile
EXPOSE 9000
```
4. **修改 healthcheck**:
```yaml
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9000/"]
```
## 重新部署
修改端口后需要重新构建:
```bash
# 停止并删除旧容器
docker stop wecom-backend wecom-frontend
docker rm wecom-backend wecom-frontend
# 重新构建并启动
cd deploy
docker compose up -d --build
# 查看日志
docker compose logs -f
```
## 验证端口
### 检查容器端口
```bash
docker ps
```
应该看到类似:
```
CONTAINER ID IMAGE PORTS
xxx deploy-backend 0.0.0.0:8888->8888/tcp
xxx deploy-frontend 0.0.0.0:8889->80/tcp
```
### 测试后端访问
```bash
curl http://localhost:8888
```
### 测试前端访问
```bash
curl http://localhost:8889/ashai-wecom-test
```
## 常见问题
### 1. 端口被占用
如果启动时报错端口被占用:
```bash
# 查看端口占用
netstat -tulpn | grep 8888
# 或使用 lsofMac/Linux
lsof -i :8888
# Windows
netstat -ano | findstr 8888
```
解决方案:
- 停止占用端口的程序
- 或修改为其他未占用的端口
### 2. 容器内外端口不一致
如果宿主机 8080 被占用,可以只修改宿主机端口:
```yaml
ports:
- "9000:8888" # 宿主机 9000 映射到容器 8888
```
这样:
- 容器内应用仍运行在 8888
- 外部通过 9000 访问
### 3. 前端无法连接后端
确保前端 Nginx 配置中的后端地址正确:
**文件**: [frontend/nginx.conf](frontend/nginx.conf)
```nginx
location /ashai-wecom-test/prod-api/ {
proxy_pass http://backend:8888/; # 使用容器名和容器内端口
...
}
```
注意:
- 容器间通信使用**容器名**和**容器内端口**
- 不是宿主机端口
## 完整的访问流程
```
用户浏览器
http://server-ip:8889/ashai-wecom-test
宿主机 8889 端口
前端容器 80 端口 (Nginx)
API 请求: /ashai-wecom-test/prod-api/*
Nginx 代理到: http://backend:8888/
后端容器 8888 端口 (Spring Boot)
返回数据
```