From a13f6059775fc60a4138376a5cade9b08dd54b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Sat, 20 Dec 2025 12:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20WebUI=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=20host=20=E5=92=8C=20port=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=94=B9=E4=B8=BA=E4=BB=8E=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E8=AF=BB=E5=8F=96=EF=BC=9B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E6=A8=A1=E6=9D=BF=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=87=B3=207.2.5=EF=BC=8C=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E8=AF=B4=E6=98=8E=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/official_configs.py | 11 ++++------- src/webui/webui_server.py | 12 ++++++------ template/bot_config_template.toml | 8 ++------ template/template.env | 6 +++++- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 1b6a73ae..38665e6d 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -599,7 +599,10 @@ class TelemetryConfig(ConfigBase): @dataclass class WebUIConfig(ConfigBase): - """WebUI配置类""" + """WebUI配置类 + + 注意: host 和 port 配置已移至环境变量 WEBUI_HOST 和 WEBUI_PORT + """ enabled: bool = True """是否启用WebUI""" @@ -607,12 +610,6 @@ class WebUIConfig(ConfigBase): mode: Literal["development", "production"] = "production" """运行模式:development(开发) 或 production(生产)""" - host: str = "0.0.0.0" - """WebUI服务器监听地址""" - - port: int = 8001 - """WebUI服务器端口""" - anti_crawler_mode: Literal["false", "strict", "loose", "basic"] = "basic" """防爬虫模式:false(禁用) / strict(严格) / loose(宽松) / basic(基础-只记录不阻止)""" diff --git a/src/webui/webui_server.py b/src/webui/webui_server.py index d2dca8dd..f7a4efa8 100644 --- a/src/webui/webui_server.py +++ b/src/webui/webui_server.py @@ -186,7 +186,7 @@ class WebUIServer: error_msg = f"❌ WebUI 服务器启动失败: 端口 {self.port} 已被占用" logger.error(error_msg) logger.error(f"💡 请检查是否有其他程序正在使用端口 {self.port}") - logger.error("💡 可以在配置文件中修改 webui.port 来更改 WebUI 端口") + logger.error("💡 可以在 .env 文件中修改 WEBUI_PORT 来更改 WebUI 端口") logger.error(f"💡 Windows 用户可以运行: netstat -ano | findstr :{self.port}") logger.error(f"💡 Linux/Mac 用户可以运行: lsof -i :{self.port}") raise OSError(f"端口 {self.port} 已被占用,无法启动 WebUI 服务器") @@ -224,7 +224,7 @@ class WebUIServer: if "address already in use" in str(e).lower() or e.errno in (98, 10048): # 98: Linux, 10048: Windows logger.error(f"❌ WebUI 服务器启动失败: 端口 {self.port} 已被占用") logger.error(f"💡 请检查是否有其他程序正在使用端口 {self.port}") - logger.error("💡 可以在配置文件中修改 webui.port 来更改 WebUI 端口") + logger.error("💡 可以在 .env 文件中修改 WEBUI_PORT 来更改 WebUI 端口") else: logger.error(f"❌ WebUI 服务器启动失败 (网络错误): {e}") raise @@ -279,9 +279,9 @@ def get_webui_server() -> WebUIServer: """获取全局 WebUI 服务器实例""" global _webui_server if _webui_server is None: - # 从配置读取 - from src.config.config import global_config - host = global_config.webui.host - port = global_config.webui.port + # 从环境变量读取 + import os + 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/bot_config_template.toml b/template/bot_config_template.toml index da0fd4d9..9b0544aa 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "7.2.4" +version = "7.2.5" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- # 如果你想要修改配置文件,请递增version的值 @@ -267,13 +267,9 @@ api_server_allowed_api_keys = [] # 新版API Server允许的API Key列表,为 enable = true [webui] # WebUI 独立服务器配置 +# 注意: WebUI 的监听地址(host)和端口(port)已移至 .env 文件中的 WEBUI_HOST 和 WEBUI_PORT enabled = true # 是否启用WebUI mode = "production" # 模式: development(开发) 或 production(生产) -host = "127.0.0.1" # WebUI 服务器监听地址 - # IPv4: 0.0.0.0 (所有IPv4接口) / 127.0.0.1 (仅本地) - # IPv6: :: (所有接口,支持IPv4+IPv6双栈) / ::1 (仅本地IPv6) - # 推荐使用 :: 实现双栈支持 -port = 8001 # WebUI 服务器端口 # 防爬虫配置 anti_crawler_mode = "basic" # 防爬虫模式: false(禁用) / strict(严格) / loose(宽松) / basic(基础-只记录不阻止) diff --git a/template/template.env b/template/template.env index 091f4ddd..23143a71 100644 --- a/template/template.env +++ b/template/template.env @@ -1,3 +1,7 @@ # 麦麦主程序配置 HOST=127.0.0.1 -PORT=8000 \ No newline at end of file +PORT=8000 + +# WebUI 服务器配置 +WEBUI_HOST=127.0.0.1 +WEBUI_PORT=8001 \ No newline at end of file