我試圖設置讓我們對使用Go編寫的負載均衡器進行加密,我嘗試了自動和手動設置,但總是出現錯誤。設置讓我們使用Go進行加密 - 握手錯誤
該域指向我們的服務器(數字海洋)正確,我甚至可以從瀏覽器打開網站沒有錯誤,也是一個ssl檢查報告沒有在這個域上的錯誤。事實是,當我從CLI的服務器上運行Go可執行文件時,我反覆出現錯誤。
- 自動(ACME/autocert)設置:
服務器代碼,當我看域從第一次瀏覽器服務器啓動後的證書和密鑰創建:
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
我得到這些錯誤:
HTTP:TLS (ip):59451:read tcp(myserver IP):443 - >(ip):59451:read:connection reset by peer
hello.ServerName empty:2017/04/01 17:14: 38 HTTP:從(IP)TLS握手錯誤:58193:ACME/autocert:丟失的服務器名
HTTP:45822::ACME/autocert:從(IP)TLS握手錯誤未配置主機
HTTP :(IP):TLS握手錯誤:58440: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
}
錯誤:
http2:服務器:錯誤從客戶端(ip)讀取前言:10319:僞造文件 「POST/HTTP/1.1 \ r \ n主機:4」
http:TLS握手錯誤來自IP):10322:EOF
HTTP:13504:讀TCP(我的服務器IP):從(IP)TLS握手錯誤443 - >(IP):13504:閱讀:連接重置由對等
http2:服務器:錯誤讀取來自客戶端(IP)前言:9672:超時等待客戶前言
有人能幫助我嗎?謝謝
如果你在開放的互聯網上有一臺服務器,你將會破損並且格式不正確的TLS請求。你是否與自己的客戶發生錯誤? – JimB
不,看起來,我只是試圖刷新頁面從鉻,它似乎並沒有觸發任何錯誤...仍然我得到了很多他們無論如何,5-20分鐘... –
你試圖運行代碼在http://stackoverflow.com/a/40494806/1465640和*只是*與您的域信息更新?並且您確定您正在通過端口443訪問服務器 – Pylinux