Module connecting outside

Maxim Dounin mdounin at
Thu Mar 9 13:16:02 UTC 2017


On Wed, Mar 08, 2017 at 08:10:25PM +0100, Antonio Nappa wrote:

> I am in the process of creating a module that connects to the outside to
> exchange data with another service, I am taking as inspiration the
> mail_module and the upstream module, basically my module is connecting
> using the ngx_event_connect_peer and handling the read and write events
> properly. I have 2 questions:
> Is this the proper way to make a module connecting to the outside?


> Would it be possible to use nginx primitives to connect through SSL?

To connect through SSL you sill have to use 
ngx_event_connect_peer(), and then have to use appropriate 
functions (ngx_ssl_create_connection(), ngx_ssl_handshake(), and 
so on) to initiate an SSL handshake.  Once handshake is complete, 
you can use the connection much like any other connection in 
nginx, using c->send(), c->send_chain() and so on.  Take a look on 
the ngx_http_upstream.c on how to do this properly.

Maxim Dounin

More information about the nginx-devel mailing list