如何将 Go 的 autocert 包与 CloudFlare 一起使用?
How can I use Go's autocert package with CloudFlare?
我尝试了 运行 来自 autocert 文档的示例代码,将其更改为使用我的域:
package main
import (
"fmt"
"log"
"net/http"
"golang.org/x/crypto/acme/autocert"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
})
log.Fatal(http.Serve(autocert.NewListener("mydomain.work"), mux))
}
在浏览器中,我看到 CloudFlare 错误提示 Error 525 SSL handshake failed
。 Go程序的输出是
2020/02/27 00:44:10 http: TLS handshake error from 172.69.22.250:26624: acme/autocert: unable to satisfy "https://acme-v02.api.letsencrypt.org/acme/authz-v3/3031814088" for domain "mydomain.work": no viable challenge type found
当我关闭 CloudFlare 的始终使用 HTTPS 功能时问题仍然存在,该功能会阻止 http-01 质询。当我在 CloudFlare 控制台中将 TLS 设置为 Off 时,它仍然存在。通过回到 NameCheap 的基本 DNS,我终于让它工作了。
我喜欢 CloudFlare 的功能,所以这让我想知道:如何让 Go 的自动认证包与 CloudFlare 一起工作?或者它是不必要的,因为我可以将自签名证书与 CloudFlare 的完全加密设置一起使用?
在 CloudFlare 上,转到 SSL/TLS,然后转到“源服务器”选项卡。单击“创建证书”按钮,他们会免费为您制作一个。您可以使用它来处理他们的完全(严格)加密设置。
我尝试了 运行 来自 autocert 文档的示例代码,将其更改为使用我的域:
package main
import (
"fmt"
"log"
"net/http"
"golang.org/x/crypto/acme/autocert"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
})
log.Fatal(http.Serve(autocert.NewListener("mydomain.work"), mux))
}
在浏览器中,我看到 CloudFlare 错误提示 Error 525 SSL handshake failed
。 Go程序的输出是
2020/02/27 00:44:10 http: TLS handshake error from 172.69.22.250:26624: acme/autocert: unable to satisfy "https://acme-v02.api.letsencrypt.org/acme/authz-v3/3031814088" for domain "mydomain.work": no viable challenge type found
当我关闭 CloudFlare 的始终使用 HTTPS 功能时问题仍然存在,该功能会阻止 http-01 质询。当我在 CloudFlare 控制台中将 TLS 设置为 Off 时,它仍然存在。通过回到 NameCheap 的基本 DNS,我终于让它工作了。
我喜欢 CloudFlare 的功能,所以这让我想知道:如何让 Go 的自动认证包与 CloudFlare 一起工作?或者它是不必要的,因为我可以将自签名证书与 CloudFlare 的完全加密设置一起使用?
在 CloudFlare 上,转到 SSL/TLS,然后转到“源服务器”选项卡。单击“创建证书”按钮,他们会免费为您制作一个。您可以使用它来处理他们的完全(严格)加密设置。