--- title: "HTTP 绑定地址配置" date: 2026-03-19 lastmod: 2026-03-19 description: "控制 HTTP 服务绑定地址的配置说明" tags: ["HTTP", "网络绑定", "安全配置"] summary: "配置项作用 # http.bind_host 配置项指定 HTTP 服务实际绑定的网络接口 IP 地址,决定在哪里监听 HTTP 连接。 是否可选 # 是 默认值 # [] (空列表,依次回退到 http.host、network.bind_host、network.host) 配置项类型 # 静态配置 - 需要重启节点才能生效 配置格式 # # 绑定到特定 IP http.bind_host: - 192.168.1.100 # 绑定到多个 IP http.bind_host: - 192.168.1.100 - 10.0.0.50 # 绑定到所有接口(生产环境不推荐) http.bind_host: - 0.0.0.0 # 使用主机名(启动时解析) http.bind_host: - server1.example.com 与 http.host 的关系 # ┌─────────────────────────────────────────────────────────┐ │ 地址解析优先级 │ └─────────────────────────────────────────────────────────┘ http.bind_host │ ├── 已设置 → 使用 http." --- ## 配置项作用 `http.bind_host` 配置项指定 HTTP 服务实际绑定的网络接口 IP 地址,决定在哪里监听 HTTP 连接。 ## 是否可选 是 ## 默认值 ``` [] (空列表,依次回退到 http.host、network.bind_host、network.host) ``` ## 配置项类型 **静态配置** - 需要重启节点才能生效 ## 配置格式 ```yaml # 绑定到特定 IP http.bind_host: - 192.168.1.100 # 绑定到多个 IP http.bind_host: - 192.168.1.100 - 10.0.0.50 # 绑定到所有接口(生产环境不推荐) http.bind_host: - 0.0.0.0 # 使用主机名(启动时解析) http.bind_host: - server1.example.com ``` ## 与 http.host 的关系 ``` ┌─────────────────────────────────────────────────────────┐ │ 地址解析优先级 │ └─────────────────────────────────────────────────────────┘ http.bind_host │ ├── 已设置 → 使用 http.bind_host │ └── 未设置 ↓ │ ▼ http.host │ ├── 已设置 → 使用 http.host │ └── 未设置 ↓ │ ▼ network.bind_host │ ├── 已设置 → 使用 network.bind_host │ └── 未设置 ↓ │ ▼ network.host ``` ## 推荐设置 | 场景 | 推荐值 | 说明 | |------|--------|------| | 生产环境 | 具体内网 IP | 明确绑定地址 | | 多网卡 | 需要的 IP 列表 | 指定每个网卡 IP | | 容器环境 | 0.0.0.0 | 容器内绑定所有接口 | | 开发环境 | 127.0.0.1 | 只允许本地访问 | | NAT 环境 | 内网 IP | 绑定内网接口 | ## 使用示例 **多网卡服务器:** ```yaml # 只绑定到特定网卡 http.bind_host: - 192.168.1.100 ``` **容器环境:** ```yaml # 绑定到所有接口 http.bind_host: - 0.0.0.0 ``` **开发环境:** ```yaml # 只允许本地访问 http.bind_host: - 127.0.0.1 ``` ## 与 http.publish_host 配合使用 ``` 客户端请求 → [http.bind_host] → 节点处理 → [http.publish_host] → 客户端连接 │ │ │ ▼ ▼ ▼ 绑定地址 内部地址 发布地址 (实际监听) (处理逻辑) (对外暴露) ``` **示例配置:** ```yaml # 绑定到内网 IP http.bind_host: - 192.168.1.100 # 发布公网 IP http.publish_host: - 203.0.113.10 ``` ## 配置验证 ```bash # 查看绑定地址 GET /_nodes?filter_path=nodes.*.http.bind_address # 查看监听端口 netstat -tuln | grep 9200 ``` ## 常见问题 **问题 1:无法从外部访问** **原因:** - 绑定到了 127.0.0.1 - 绑定的 IP 不在正确的网卡上 **解决方案:** ```yaml http.bind_host: - 192.168.1.100 ``` **问题 2:多网卡绑定错误** **解决方案:** ```yaml # 明确指定所有需要的 IP http.bind_host: - 192.168.1.100 - 10.0.0.50 ``` ## 安全建议 **生产环境最佳实践:** 1. **避免绑定所有接口** ```yaml # 不推荐 http.bind_host: - 0.0.0.0 # 推荐 http.bind_host: - 192.168.1.100 ``` 2. **使用内网 IP** ```yaml http.bind_host: - 10.0.0.10 ``` 3. **配合防火墙** ```bash # 限制访问来源 firewall-cmd --permanent --add-rich-rule=' rule family="ipv4" source address="10.0.0.0/8" port protocol="tcp" port="9200" accept ' ``` ## 注意事项 1. **静态配置**:修改绑定地址需要重启节点 2. **优先级高**:http.bind_host 优先级高于 http.host 3. **地址解析**:主机名在启动时解析为 IP 4. **安全考虑**:生产环境应绑定具体 IP 5. **回退机制**:未设置时依次回退到其他配置 ## 相关配置项 | 配置项 | 默认值 | 说明 | |-------|-------|------| | `http.host` | [] | HTTP 主机地址 | | `http.publish_host` | [] | 对外发布地址 | | `network.bind_host` | [] | 全局绑定地址 | | `network.host` | [] | 全局网络地址 | ## 完整配置示例 ```yaml # easysearch.yml # 生产环境配置 http.bind_host: - 192.168.1.100 http.publish_host: - search.example.com http.port: 9200 ```