本文介绍了websocket - 连接建立错误:net :: ERR_INSECURE_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法连接到websocket服务器。我使用完全相同的 private.key
和 public.crt
,我使用 nginx
证书是自签名的,但可以通过nginx通过HTTPS与网站的其他部分正常工作
$ b websocket服务器在使用
ws:// <当$ http.ListenAndServe()
的行被取消注释时,code> <$ c (
flag
fmt
log
net / http
)
$ const port uint = 8000
func main(){
host:= parse_flags()
hub:= newHub()
go hub.run()
http.HandleFunc(/,func(w http.ResponseWriter,r * http.Request){
serve(hub,w, r)
$)
server_host:= fmt.Sprintf(%s:%d,host,PORT)
log.Println on:,server_host)
err:= http.ListenAndServeTLS(server_h ost,fmt.Sprintf(/ var / ini / ssl /%s / public.crt,主机),fmt.Sprintf(/ var / ini / ssl /%s / private.key,主机)
// err:= http.ListenAndServe(server_host,nil)
if err!= nil {
log.Fatal(ListenAndServe:,err)
}
}
解决方案
现在Chrome似乎最新版本拒绝SHA-1证书是不安全的。您可能需要转移到SHA-2证书。
Can't connect to websocket server..
I use the exact same private.key
and public.crt
that I use with nginx
The cert is self-signed but works fine with the rest of the website over HTTPS via nginx
The websocket server works when using ws://
when the line with http.ListenAndServe()
is uncommented
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
const PORT uint = 8000
func main(){
host := parse_flags()
hub := newHub()
go hub.run()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
serve(hub, w, r)
})
server_host := fmt.Sprintf("%s:%d", host, PORT)
log.Println("Server listening on:", server_host)
err := http.ListenAndServeTLS(server_host, fmt.Sprintf("/var/ini/ssl/%s/public.crt", host), fmt.Sprintf("/var/ini/ssl/%s/private.key", host), nil)
//err := http.ListenAndServe(server_host, nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
解决方案
It looks like newest version of Chrome now rejects SHA-1 certs as being insecure. You probably need to move to SHA-2 certs.
这篇关于websocket - 连接建立错误:net :: ERR_INSECURE_RESPONSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!