Адрес с веба
https://mysite.ru/ws
nginx
...
location /ws/ {
include proxy_params;
proxy_pass
127.0.0.1:8090/ws;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
}
....
в коде:
func wsEndpoint(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
}
log.Println("Client Connected")
err = ws.WriteMessage(1, []byte("Hi Client, URA!"))
if err != nil {
log.Println(err)
}
reader(ws)
}