Files
aiagent/防火墙配置说明.md
2026-01-19 00:09:36 +08:00

133 lines
2.9 KiB
Markdown
Raw 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.
# 防火墙配置说明
## 问题确认
**已确认是防火墙问题**
- 本地访问 `localhost:8037` ✅ 正常
- 公网访问 `101.43.95.130:8037` ❌ 连接被拒绝
## 解决方案
### 方法1使用脚本自动配置推荐
```bash
# 运行开放端口脚本
sudo bash /home/renjianbo/aiagent/开放端口脚本.sh
```
### 方法2手动配置
#### 如果使用 firewalld (CentOS/RHEL 7+)
```bash
# 开放端口
sudo firewall-cmd --permanent --add-port=8037/tcp
sudo firewall-cmd --permanent --add-port=8038/tcp
# 重新加载配置
sudo firewall-cmd --reload
# 验证
sudo firewall-cmd --list-ports
```
#### 如果使用 ufw (Ubuntu/Debian)
```bash
# 开放端口
sudo ufw allow 8037/tcp
sudo ufw allow 8038/tcp
# 验证
sudo ufw status
```
#### 如果使用 iptables
```bash
# 开放端口
sudo iptables -I INPUT -p tcp --dport 8037 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8038 -j ACCEPT
# 保存规则(根据系统不同)
# CentOS/RHEL:
sudo service iptables save
# Debian/Ubuntu:
sudo iptables-save | sudo tee /etc/iptables/rules.v4
```
### 方法3云服务器安全组配置重要
如果使用云服务器腾讯云、阿里云、AWS等**必须在云控制台配置安全组规则**
#### 腾讯云
1. 登录腾讯云控制台
2. 进入「云服务器」->「安全组」
3. 找到对应的安全组,点击「修改规则」
4. 添加入站规则:
- 类型:自定义
- 协议端口TCP:8037
- 来源0.0.0.0/0或指定IP
- 策略:允许
5. 同样添加 8038 端口
#### 阿里云
1. 登录阿里云控制台
2. 进入「ECS」->「网络与安全」->「安全组」
3. 配置规则 -> 入方向 -> 添加安全组规则
4. 端口范围8037/8037授权对象0.0.0.0/0
## 验证
配置完成后,测试:
```bash
# 从服务器本地测试
curl http://localhost:8037/health
# 从公网测试(需要从其他机器或使用在线工具)
curl http://101.43.95.130:8037/health
```
应该返回:`{"status":"healthy"}`
## 检查当前端口监听状态
```bash
# 检查端口是否监听
netstat -tlnp | grep 8037
# 或
ss -tlnp | grep 8037
# 应该看到:
# tcp 0 0 0.0.0.0:8037 ... LISTEN
```
## 常见问题
### Q: 配置了防火墙,但还是无法访问?
A: 检查以下几点:
1. **云服务器安全组**:必须同时配置云控制台的安全组
2. **端口映射**:确认 Docker 端口映射正确(`8037:8000`
3. **服务状态**:确认后端服务正在运行
4. **IP地址**确认公网IP地址正确
### Q: 如何确认是防火墙问题?
A: 从服务器本地测试:
```bash
# 本地访问正常
curl http://localhost:8037/health
# 公网访问被拒绝
curl http://101.43.95.130:8037/health
# 返回: Connection refused
```
---
**状态**: ⚠️ 需要配置防火墙
**下一步**: 运行开放端口脚本或手动配置防火墙规则