From 909f8c96e258fd62b056418bc97086caf4a13e41 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:48:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E7=9B=91=E5=90=AC=20IPv4=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#2750)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server/server.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/server/server.go b/backend/server/server.go index bef3dd270..075639d11 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "encoding/gob" "fmt" + "net" "net/http" "os" "path" @@ -54,6 +55,13 @@ func Start() { Addr: global.CONF.System.BindAddress + ":" + global.CONF.System.Port, Handler: rootRouter, } + ln, err := net.Listen(tcpItem, server.Addr) + if err != nil { + panic(err) + } + type tcpKeepAliveListener struct { + *net.TCPListener + } if global.CONF.System.SSL == "enable" { certificate, err := os.ReadFile(path.Join(global.CONF.System.BaseDir, "1panel/secret/server.crt")) if err != nil { @@ -71,12 +79,12 @@ func Start() { Certificates: []tls.Certificate{cert}, } global.LOG.Infof("listen at https://%s:%s [%s]", global.CONF.System.BindAddress, global.CONF.System.Port, tcpItem) - if err := server.ListenAndServeTLS("", ""); err != nil { + + if err := server.ServeTLS(tcpKeepAliveListener{ln.(*net.TCPListener)}, "", ""); err != nil { panic(err) } } else { - global.LOG.Infof("listen at http://%s:%s [%s]", global.CONF.System.BindAddress, global.CONF.System.Port, tcpItem) - if err := server.ListenAndServe(); err != nil { + if err := server.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)}); err != nil { panic(err) } }