小编csa*_*ath的帖子

球童代理的WebSocket握手错误

我正在尝试启动chrome 浏览器客户端和服务器之间的websocket连接

我的实施概述:有一组不同的启动和运行项目。主项目是所有其他项目的中心,它处理所有http请求,路由和到其他子项目的代理。这些所有项目都使用负载平衡器。我的尝试是创建一个从chrom浏览器到一个子项目的websocket连接。

球童版本:0.9.3
websocket库:github.com/gorilla/websocket

主项目的球童配置:

https://{$DOMAIN_NAME}/analytics/ {
    tls ../resources/security/server.pem ../resources/security/server.key
    proxy /  https://localhost:8107/analytics {
       websocket
       insecure_skip_verify
    }
}
Run Code Online (Sandbox Code Playgroud)

子项目的球童配置:

localhost:{$ANALYTICS_CADDY_PORT}/analytics {
    root  webapps/analytics
    gzip
    ext    .html
    tls {$ANALYTICS_CERTIFICATE_FILE} {$ANALYTICS_KEY_FILE}
    proxy  /api https://localhost:{$ANALYTICS_HTTPS_PORT} {
         websocket
         insecure_skip_verify

    }
}
Run Code Online (Sandbox Code Playgroud)

在分析子项目中,“ / api / ws”将触发CreateSocketConnection()方法。

//Starting the API server
    router := routes.NewRouter()
    http.Handle("/", router)
    http.HandleFunc("/api/ws", api.CreateSocketConnection)
Run Code Online (Sandbox Code Playgroud)

CreateSocketConnection实现:

func CreateSocketConnection(w http.ResponseWriter, r *http.Request) {
    var upgrader = websocket.Upgrader{
        ReadBufferSize:  1024,
        WriteBufferSize: 1024,
    }
    _, err = upgrader.Upgrade(w, r, …
Run Code Online (Sandbox Code Playgroud)

websocket gorilla caddy

5
推荐指数
1
解决办法
502
查看次数

标签 统计

caddy ×1

gorilla ×1

websocket ×1