我使用wss://
中去试图建立一个安全的WebSocket服务器(acme/autocert
)。该程序启动,但是当我尝试连接到它,我得到以下错误:
http: TLS handshake error from <IP>: acme/autocert:
unable to authorize "<my domain>"; challenge "tls-alpn-01" failed with error:
acme: authorization error for <my domain>: 403 urn:acme:error:unauthorized:
Cannot negotiate ALPN protocol "acme-tls/1" for tls-alpn-01 challenge
这是我使用启动的WebSocket服务器的代码:
func Run() {
hub = newHub()
go hub.run()
mux := http.NewServeMux()
mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(hub, w, r)
})
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
Cache: autocert.DirCache("certs"),
}
server := &http.Server{
Addr: ":8080",
Handler: mux,
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
go server.ListenAndServeTLS("", "")
}
它应该自动获得一个新的证书时,有没有在高速缓存(certs
文件夹)。该错误消息告诉我,有一个问题,同时创造了新的证书时谈判的协议。我需要的地方添加支持的协议?
我不知道你有什么问题,但尝试添加HostPolicy为了让该经理知道哪些主机被允许响应。这里的例子https://github.com/kjk/go-cookbook/blob/master/free-ssl-certificates/main.go#L77
注:作为一个建议尽量使用443或8443作为一个安全的港口。