栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何为Go服务器应用程序设置Let's Encrypt

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何为Go服务器应用程序设置Let's Encrypt

这是使用我发现的Go and Let’s Encrypt证书对HTTPS服务器进行的最小自动设置:

package mainimport (    "crypto/tls"    "log"    "net/http"    "golang.org/x/crypto/acme/autocert")func main() {    certManager := autocert.Manager{        prompt:     autocert.AcceptTOS,        HostPolicy: autocert.HostWhitelist("example.com"), //Your domain here        Cache:      autocert.DirCache("certs"), //Folder for storing certificates    }    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {        w.Write([]byte("Hello world"))    })    server := &http.Server{        Addr: ":https",        TLSConfig: &tls.Config{ GetCertificate: certManager.GetCertificate,        },    }    go http.ListenAndServe(":http", certManager.HTTPHandler(nil))    log.Fatal(server.ListenAndServeTLS("", "")) //Key and cert are coming from Let's Encrypt}

有关autocert软件包的更多信息:链接

编辑:由于letencrypt安全性问题,需要使http可用,在此处了解更多信息。作为此修复程序的奖励,我们现在具有http->
https重定向。如果您已收到旧示例的证书,则旧示例将继续工作,但是对于新站点,它将中断。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/484243.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号