我正在尝试设置--让我们在一个用Go编写的负载均衡器上加密,我尝试了自动和手动设置,但是我总是会出错。
域是正确指向我们的服务器(数字海洋),我甚至可以打开网站从浏览器没有错误,还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我明白这些错误:
然后,我还尝试手动创建证书(成功地),并简单地使用该代码,我一次又一次地得到错误:
服务器代码是:
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
}错误:
有人能帮帮我吗?谢谢
发布于 2018-01-28 03:19:31
正如JimB和其他人在评论中所说的那样,这可能是错误请求的结果。当使用https://www.ssllabs.com/ssltest/测试站点的https配置时,将记录无效请求。一个好的测试分数可以给你信心,日志消息是良性的,可以安全地被忽略。
此外,acme/autocert软件包正在迅速发展(2018年1月),请检查您的版本是最新的。
https://stackoverflow.com/questions/43161559
复制相似问题