What is the best way to add a socket to nginx web server?

胡聪 (hucc) hucong.c at foxmail.com
Thu Mar 23 12:46:32 UTC 2017


Maybe you need to write a module where ngx_http_init_connection() should be
rewritten/imitated after the imitation of ngx_event_connect_peer(). You can add
some configuration items or introduce a timer which can restart/keep the TCP

And if OpenResty is familiar to you, a simpler way (lua not c) is also possible.

------------------ Original ------------------
From:  "Ottavio Campana";<o.campana at videotec.com>;
Date:  Mar 23, 2017
To:  "nginx-devel at nginx.org"<nginx-devel at nginx.org>;
Subject:  What is the best way to add a socket to nginx web server?

Hello everybody,

I am trying to understand if I can use/change nginx to solve a problem related to a very particular scenario

I have this scenario:

nginx web server <--> router with NAT <--> client running with a public IP address

I cannot configure NAT on the router, so setting port forwarding is not an option.

My idea is to have a small program that starts a TCP connection towards the client and that passes the socket descriptor to the nginx web server.

Basically the whole procedure can be summarized as follows:
1) the helper program, running on the same host of nginx, starts the TCP connection and punch holes the NAT
2) the client accepts the connection
3) the helper program passes the socket descriptor to the nginx web server by using a AF_UNIX socket
4) nginx receives the socket and adds this socket to it set of sockets
5) the client can now start sending HTTP requests to the webserver, as normally

So, the question is: is there a preferred/already existing solution/infrastructure in nginx to do this?

Thank you

nginx-devel mailing list
nginx-devel at nginx.org

More information about the nginx-devel mailing list