Welcome! Log In Create A New Profile

Advanced

Is it possible to configure socket connection(not web) in Nginx reverse proxy server

June 27, 2022 12:47AM
Hi all, 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", "2.221.29.137:9988")
_, 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", "2.221.29.137: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

stream {
server {
auth_basic off;
proxy_ssl off;
listen 80;
#TCP traffic will be forwarded to the proxy_pass #proxy_pass 3.111.69.167:9988;
proxy_pass 127.0.0.1:8899;
}
}

I want to open Port 80 and Internally proxy pass to my server,
currently getting 400 status code, when I do this, and its not passing my request to my server
Can you pls help Thank you
Subject Author Posted

Is it possible to configure socket connection(not web) in Nginx reverse proxy server

mikecon June 27, 2022 12:47AM

Re: Is it possible to configure socket connection(not web) in Nginx reverse proxy server

Sergey A. Osokin June 27, 2022 10:14AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready