From 880ffc2a58ae7422e9a56d7dce10be5707e531ce Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 17:49:32 +0800 Subject: [PATCH] fix --- proxyserver/main.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/proxyserver/main.go b/proxyserver/main.go index ac033fdd..f1fcec72 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "fmt" "io" "io/ioutil" @@ -41,6 +42,8 @@ func SetCors(w http.ResponseWriter, r *http.Request) { var pathdict sync.Map = sync.Map{} func main() { + log.SetFlags(log.Llongfile) + // 将静态资源路径存储到pathdict pathdict.Store("/css", true) pathdict.Store("/fonts", true) @@ -114,7 +117,34 @@ func main() { ServerAddress := ":9900" log.Println("listen on ", ServerAddress) - log.Fatal(http.ListenAndServe(ServerAddress, mux)) + + keydata, err := os.ReadFile("/opt/server.fusen.3718.cn.key") + if err != nil { + panic(err) + } + + pemdata, err := os.ReadFile("/opt/server.fusen.3718.cn.pem") + if err != nil { + panic(err) + } + + cert, err := tls.X509KeyPair(pemdata, keydata) + if err != nil { + panic(err) + } + + tlscfg := &tls.Config{ + Certificates: []tls.Certificate{cert}, + MinVersion: tls.VersionTLS12, + MaxVersion: tls.VersionTLS13, + } + serv := http.Server{ + Addr: ServerAddress, + Handler: mux, + TLSConfig: tlscfg, + } + + log.Fatal(serv.ListenAndServeTLS("", "")) } // 后端服务的类型