Mar*_*o M 5 ssl ssl-certificate go lets-encrypt
我正在尝试在用 Go 编写的负载均衡器上设置让我们加密,我尝试了自动和手动设置,但总是出错。
该域正确指向我们的服务器(Digital Ocean),我什至可以从浏览器中打开该站点而不会出错,而且 ssl 检查也没有报告此域上的错误。事实是,当我从 CLI 在服务器上运行 Go 可执行文件时,我反复出现错误。
服务器代码是,服务器启动后第一次从浏览器查看域时创建的证书和密钥:
go func() {
log.Printf("Staring HTTP service on %s ...", ":80")
http.HandleFunc("/*", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://" + app.Cfg.S_HOST + ":443" + r.RequestURI, http.StatusMovedPermanently)
}))
if err := http.ListenAndServe(":80", nil); err != nil {
errs <- err
}
}()
log.Printf("Staring HTTPS service on %s ...", ":443")
http.HandleFunc("/hello", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is an example server.\n"))
}))
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(app.Cfg.S_HOST), //your domain here
Cache: autocert.DirCache("certs"), //folder for storing certificates
}
server := &http.Server{
Addr: ":443",
TLSConfig: &tls.Config{
ServerName: app.Cfg.S_HOST,
GetCertificate: certManager.GetCertificate,
},
}
if err := server.ListenAndServeTLS("", ""); err != nil {
print(err.Error())
} //key and cert are comming from Let's Encrypt
Run Code Online (Sandbox Code Playgroud)
我收到这些错误:
http: 来自 (ip):59451 的 TLS 握手错误:读取 tcp (myserver IP):443->(ip):59451: 读取:连接由对等方重置
hello.ServerName empty:2017/04/01 17:14:38 http: TLS 握手错误来自 (ip):58193: acme/autocert: 缺少服务器名称
http:来自 (ip):45822 的 TLS 握手错误:acme/autocert:未配置主机
http:来自 (ip):58440 的 TLS 握手错误:EOF
然后我还尝试手动(成功)创建证书并简单地使用该代码,我一次又一次地收到错误:
服务器代码是:
go func() {
log.Printf("Staring HTTP service on %s ...", ":80")
http.HandleFunc("/*", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://" + app.Cfg.S_HOST + ":443" + r.RequestURI, http.StatusMovedPermanently)
}))
if err := http.ListenAndServe(":80", nil); err != nil {
errs <- err
}
}()
log.Printf("Staring HTTPS service on %s ...", ":443")
http.HandleFunc("/hello", http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is an example server.\n"))
}))
// ssl["cert"] and ssl["key"] are the cert and key path (letsencrypt/live...)
if err := http.ListenAndServeTLS(sslAddr, ssl["cert"], ssl["key"], nil); err != nil {
errs <- err
}
Run Code Online (Sandbox Code Playgroud)
错误:
http2:服务器:从客户端 (ip) 读取序言时出错:10319:虚假问候语“POST / HTTP/1.1\r\nHost: 4”
http:来自 (ip):10322 的 TLS 握手错误:EOF
http: TLS 握手错误来自 (ip):13504: read tcp (my server ip):443->(ip):13504: read: connection reset by peer
http2:服务器:从客户端(ip)读取序言时出错:9672:等待客户端序言超时
有人能帮助我吗?谢谢
正如 JimB 和其他人在评论中所说,这可能是错误请求的结果。使用https://www.ssllabs.com/ssltest/测试站点的 https 配置时,将记录无效请求。良好的测试分数可以让您确信日志消息是良性的并且可以安全地忽略。
此外,acme/autocert软件包正在快速发展(截至 2018 年 1 月),请检查您的版本是否是最新的。
| 归档时间: |
|
| 查看次数: |
4818 次 |
| 最近记录: |