From 32a6d1a520e5007847f0786b3b7b3b643679de23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9B=A6?= <2584059816@qq.com> Date: Sun, 14 Dec 2025 16:40:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9webui=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=9A=B4=E9=9C=B2=E7=AB=AF=E5=8F=A3=E4=B8=BA?= =?UTF-8?q?127.0.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 WebUI 服务的默认监听地址从 0.0.0.0 修改为 127.0.0.1,以提升安全性,默认仅允许本地访问。同步调整了相关日志提示以及 template.env 中的注释说明,明确如何在需要时显式开启对外访问。 --- src/main.py | 4 ++-- src/webui/webui_server.py | 6 +++--- template/template.env | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 3bcc9695..58403f65 100644 --- a/src/main.py +++ b/src/main.py @@ -59,12 +59,12 @@ class MainSystem: if webui_mode == "development": logger.info("📝 WebUI 开发模式已启用") - logger.info("🌐 后端 API 将运行在 http://0.0.0.0:8001") + logger.info("🌐 后端 API 将运行在配置的地址(默认 http://127.0.0.1:8001)") logger.info("💡 请手动启动前端开发服务器: cd MaiBot-Dashboard && bun dev") logger.info("💡 前端将运行在 http://localhost:7999") else: logger.info("✅ WebUI 生产模式已启用") - logger.info("🌐 WebUI 将运行在 http://0.0.0.0:8001") + logger.info("🌐 WebUI 将运行在配置的地址(默认 http://127.0.0.1:8001)") logger.info("💡 请确保已构建前端: cd MaiBot-Dashboard && bun run build") except Exception as e: diff --git a/src/webui/webui_server.py b/src/webui/webui_server.py index ba6b7480..12b6587c 100644 --- a/src/webui/webui_server.py +++ b/src/webui/webui_server.py @@ -1,4 +1,4 @@ -"""独立的 WebUI 服务器 - 运行在 0.0.0.0:8001""" +"""独立的 WebUI 服务器 - 默认运行在 127.0.0.1:8001""" import os import asyncio @@ -16,7 +16,7 @@ logger = get_logger("webui_server") class WebUIServer: """独立的 WebUI 服务器""" - def __init__(self, host: str = "0.0.0.0", port: int = 8001): + def __init__(self, host: str = "127.0.0.1", port: int = 8001): self.host = host self.port = port self.app = FastAPI(title="MaiBot WebUI") @@ -178,7 +178,7 @@ def get_webui_server() -> WebUIServer: global _webui_server if _webui_server is None: # 从环境变量读取配置 - host = os.getenv("WEBUI_HOST", "0.0.0.0") + host = os.getenv("WEBUI_HOST", "127.0.0.1") port = int(os.getenv("WEBUI_PORT", "8001")) _webui_server = WebUIServer(host=host, port=port) return _webui_server diff --git a/template/template.env b/template/template.env index b6dd0e5c..eeb71717 100644 --- a/template/template.env +++ b/template/template.env @@ -5,5 +5,5 @@ PORT=8000 # WebUI 独立服务器配置 WEBUI_ENABLED=true WEBUI_MODE=production # 模式: development(开发) 或 production(生产) -WEBUI_HOST=0.0.0.0 # WebUI 服务器监听地址 +WEBUI_HOST=127.0.0.1 # WebUI 服务器监听地址(默认仅本地访问,设置为0.0.0.0可允许外部访问) WEBUI_PORT=8001 # WebUI 服务器端口 \ No newline at end of file