fix:修改webui默认配置暴露端口为127.0.0.1

将 WebUI 服务的默认监听地址从 0.0.0.0 修改为 127.0.0.1,以提升安全性,默认仅允许本地访问。同步调整了相关日志提示以及 template.env 中的注释说明,明确如何在需要时显式开启对外访问。
This commit is contained in:
陈曦
2025-12-14 16:40:37 +08:00
parent a5dbbcc10a
commit 32a6d1a520
3 changed files with 6 additions and 6 deletions

View File

@@ -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:

View File

@@ -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