How do I ListenAndServeTLS with multiple domains? I see the function accepts a cert and key file, but I believe the key file may only contain a single private key. I have a few private keys, for different certificate chains.
2条回答 默认 最新
- doujiao2014 2015-08-24 14:29关注
http.ListenAndServeTLS
is meant to be present a bare minimal configuration. If you want to add other options, you can create anhttp.Server
with a customtls.Config
. You can then either manually map names intls.Config.NameToCertificate
, or callBuildNameToCertificate()
to build the map programatically.You can still use
Server.ListenAndServeTLS
however, since it will load the certs in the config as well a cert passed in via the methods args.cfg := &tls.Config{} cert, err := tls.LoadX509KeyPair("cert_one.pem", "key_one.pem") if err != nil { log.Fatal(err) } cfg.Certificates = append(cfg.Certificates, cert) // keep adding remaining certs to cfg.Certificates cfg.BuildNameToCertificate() server := http.Server{ Addr: "127.0.0.1:443", Handler: myHandler, TLSConfig: cfg, } server.ListenAndServeTLS("", "")
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥17 pro*C预编译“闪回查询”报错SCN不能识别
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向