--- title: "HTTP 发布地址配置" date: 2026-01-29 lastmod: 2026-01-29 description: "控制 HTTP 对外发布地址的配置说明" tags: ["HTTP", "网络配置", "多网卡"] summary: "配置项作用 # http.publish_host 配置项指定向客户端发布的 HTTP 服务主机地址,用于告诉客户端如何连接回服务器。 是否可选 # 是 默认值 # [] (空列表,依次回退到 http.bind_host、http.host、network.publish_host、network.host) 配置项类型 # 静态配置 - 需要重启节点才能生效 配置格式 # # 发布主机名 http.publish_host: - search.example.com # 发布特定 IP http.publish_host: - 203.0.113.10 # 发布多个地址 http.publish_host: - search1.example.com - search2.example.com 与 http.bind_host 的区别 # ┌─────────────────────────────────────────────────────────┐ │ 绑定地址 vs 发布地址 │ └─────────────────────────────────────────────────────────┘ http.bind_host http.publish_host │ │ ▼ ▼ 实际监听的地址 对外发布的地址 (物理接口) (客户端使用) │ │ └──────┐ ┌───────┘ │ │ ▼ ▼ [内部网络] [外部网络] 关键区别:" --- ## 配置项作用 `http.publish_host` 配置项指定向客户端发布的 HTTP 服务主机地址,用于告诉客户端如何连接回服务器。 ## 是否可选 是 ## 默认值 ``` [] (空列表,依次回退到 http.bind_host、http.host、network.publish_host、network.host) ``` ## 配置项类型 **静态配置** - 需要重启节点才能生效 ## 配置格式 ```yaml # 发布主机名 http.publish_host: - search.example.com # 发布特定 IP http.publish_host: - 203.0.113.10 # 发布多个地址 http.publish_host: - search1.example.com - search2.example.com ``` ## 与 http.bind_host 的区别 ``` ┌─────────────────────────────────────────────────────────┐ │ 绑定地址 vs 发布地址 │ └─────────────────────────────────────────────────────────┘ http.bind_host http.publish_host │ │ ▼ ▼ 实际监听的地址 对外发布的地址 (物理接口) (客户端使用) │ │ └──────┐ ┌───────┘ │ │ ▼ ▼ [内部网络] [外部网络] ``` **关键区别:** - `http.bind_host` - 服务实际监听的接口 - `http.publish_host` - 告诉客户端如何连接 ## 地址解析优先级 ``` http.publish_host │ ├── 已设置 → 使用 http.publish_host │ └── 未设置 ↓ │ ▼ http.bind_host │ ├── 已设置 → 使用 http.bind_host │ └── 未设置 ↓ │ ▼ http.host │ └── 未设置 ↓ │ ▼ network.publish_host │ └── 未设置 ↓ │ ▼ network.host ``` ## 推荐设置 | 场景 | 推荐值 | 说明 | |------|--------|------| | 单网卡 | 与 bind_host 相同 | 简化配置 | | 多网卡 | 客户端可访问的地址 | 使用正确的接口 | | NAT 环境 | 公网 IP 或域名 | 客户端需要公网地址 | | 负载均衡 | 负载均衡器地址 | 通过 LB 访问 | | 云环境 | 公网主机名 | 使用云提供商的 DNS | ## 使用示例 **NAT 环境:** ```yaml # 内网绑定 http.bind_host: - 192.168.1.100 # 外网发布 http.publish_host: - 203.0.113.10 ``` **负载均衡环境:** ```yaml # 绑定到内网 IP http.bind_host: - 10.0.1.50 # 发布负载均衡器地址 http.publish_host: - search.example.com ``` **云环境:** ```yaml # 绑定私有 IP http.bind_host: - 172.16.0.10 # 发布云主机名 http.publish_host: - ec2-xx-xx-xx-xx.compute.amazonaws.com ``` **多网卡服务器:** ```yaml # 绑定到内网 IP http.bind_host: - 192.168.1.100 # 发布到外网 IP http.publish_host: - 203.0.113.10 ``` ## 配置验证 ```bash # 查看发布地址 GET /_nodes?filter_path=nodes.*.http.publish_address # 查看完整 HTTP 信息 GET /_nodes/http ``` ## 常见问题 **问题 1:客户端无法连接** **原因:** - 发布的地址不可达 - 发布的是内网 IP **解决方案:** ```yaml http.publish_host: - search.example.com ``` **问题 2:多网卡连接错误** **解决方案:** ```yaml # 明确设置正确的发布地址 http.bind_host: - 192.168.1.100 http.publish_host: - 203.0.113.10 ``` ## 最佳实践 1. **使用 DNS 名称而非 IP** ```yaml # 推荐 http.publish_host: - search.example.com # 不推荐(IP 可能变化) http.publish_host: - 203.0.113.10 ``` 2. **确保可达性** ```yaml # 确保客户端可以访问发布的地址 http.publish_host: - search.example.com ``` 3. **保持一致性** ```yaml # 集群中所有节点使用相同的发布模式 ``` ## 注意事项 1. **静态配置**:修改发布地址需要重启节点 2. **可达性**:确保客户端能访问发布的地址 3. **DNS 优先**:推荐使用 DNS 名称而非 IP 4. **回退机制**:未设置时自动使用绑定地址 5. **集群通信**:不影响节点间通信(使用 transport) ## 相关配置项 | 配置项 | 默认值 | 说明 | |-------|-------|------| | `http.bind_host` | [] | 实际绑定地址 | | `http.host` | [] | HTTP 主机地址 | | `http.publish_port` | -1 | 发布端口 | | `transport.publish_host` | [] | 传输发布地址 | ## 完整配置示例 ```yaml # easysearch.yml # NAT 环境配置 http.bind_host: - 192.168.1.100 http.publish_host: - search.example.com http.port: 9200 http.publish_port: 9200 # 负载均衡环境配置 http.bind_host: - 10.0.1.50 http.publish_host: - search.example.com ```