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