From 9e784c29afe411496ca87cd925e6c16b930549fa Mon Sep 17 00:00:00 2001 From: yuuki-nya <47957260+yuuki-nya@users.noreply.github.com> Date: Sat, 23 Nov 2024 11:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8SSL=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=A4=87=E7=94=A8HTTP=E7=AB=AF=E5=8F=A3=E5=8F=AF?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20(#510)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 16 ++++++++-------- structs/structs.go | 1 + template/config_template.go | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 8425b4a8..d72a8c9e 100644 --- a/main.go +++ b/main.go @@ -567,18 +567,18 @@ func main() { } }() - // 如果主服务器使用443端口,同时在一个新的goroutine中启动444端口的HTTP服务器 todo 更优解 - if serverPort == "443" { + // 如果主服务器使用443端口或conf.Settings.ForceSSL为true,同时在一个新的goroutine中启动conf.Settings.HttpPortAfterSSL端口的HTTP服务器 + if serverPort == "443" || conf.Settings.ForceSSL { go func() { - // 创建另一个http.Server实例(用于444端口) - httpServer444 := &http.Server{ - Addr: "0.0.0.0:444", + // 创建另一个http.Server实例(用于conf.Settings.HttpPortAfterSSL端口) + httpServerHttpPortAfterSSL := &http.Server{ + Addr: "0.0.0.0:" + conf.Settings.HttpPortAfterSSL, Handler: r, } - // 启动444端口的HTTP服务器 - if err := httpServer444.ListenAndServe(); err != nil && err != http.ErrServerClosed { - log.Fatalf("listen (HTTP 444): %s\n", err) + // 启动conf.Settings.HttpPortAfterSSL端口的HTTP服务器 + if err := httpServerHttpPortAfterSSL.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("listen (HTTP %s): %s\n", conf.Settings.HttpPortAfterSSL, err) } }() } diff --git a/structs/structs.go b/structs/structs.go index 54c80de1..e2ff14a0 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -73,6 +73,7 @@ type Settings struct { WebhookPath string `yaml:"webhook_path"` WebhookPrefixIp []string `yaml:"webhook_prefix_ip"` ForceSSL bool `yaml:"force_ssl"` + HttpPortAfterSSL string `yaml:"http_port_after_ssl"` //日志类 DeveloperLog bool `yaml:"developer_log"` LogLevel int `yaml:"log_level"` diff --git a/template/config_template.go b/template/config_template.go index 2f2962e7..14da86b4 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -88,6 +88,7 @@ settings: webhook_path : "webhook" #webhook监听的地址,默认\webhook webhook_prefix_ip : [] #默认为空,通过webhook进行签名验证来源,设置时,只允许ip前缀的请求,不验证签名. 2024年11月22日最近的webhookip都是 183.47.105. 开始的. force_ssl : false #默认当port设置为443时启用ssl,true可以在其他port设置下强制启用ssl. + http_port_after_ssl : "444" # 指定启动SSL之后的备用HTTP服务器的端口号,默认为444 #日志类 developer_log : false #开启开发者日志 默认关闭