I have a CLI client and server written in Go Currently, they are communicating via a socket connection and it's a server streaming connection Now I want to have an Nginx proxy between these two
Is it possible to configure the normal socket connection in Nginx? How do that, and what all code changes & configuration changes I need to do
There's not much on the internet on this on socket connection in Nginx I was wondering if it's possible or not
//my client code:
func getStreammessages() {
connection, err := net.Dial("tcp", "127.0.0.1:8888")
_, err = connection.Write([]byte(sendIDtoServertoGetStream))
for {
mLen, err := connection.Read(buffer)
//some logic to print the message stream
}
}
//my server code:
func StartStreamServer() {
server, err := net.Listen("tcp", "127.0.0.2:9988")
defer server.Close()
for {
connection, err := server.Accept()
go registerClient(connection)
}
}
func registerClient(connection net.Conn) {
buffer := make([]byte, 1024)
mLen, err := connection.Read(buffer)
var sendIDtoServertoGetStream message
err = json.Unmarshal(buffer[:mLen], &sendIDtoServertoGetStream)
}
//strem to client from message queue
func StreamMessageToCliCLient(connection net.Conn) {
_, err = connection.Write(messageString)
}
Have anyone done this before
currently, I am doing this in my Nginx (nginx.conf file) which is running in the same VM as my server
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream wsbackend {
server 127.0.0.2:9988;
}
server {
listen 8888;
location /{
auth_basic off;
proxy_ssl off;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass wsbackend;
}
location /v1/config {
proxy_pass http://$CONFIG_MGMT_HOST:$CONFIG_MGMT_PORT/v1/config;
}
}
}
I want to open Port 8888 Internally proxy pass to my server, with this setup, currently getting 400 error in log, Can you pls help Thank you