Proxying module query

Piotr Sikora piotr.sikora at frickle.com
Thu Jan 7 03:42:41 MSK 2010


> I'm struggling a bit to understand how a module can indicate which server 
> to
> issue a request to - the example proxy module code presumably does this 
> via
> the config for the upstream module.  If I'm just interested in sending a
> query to a known host/port, what's the best way of doing this?

Using function registered with r->upstream->peer.get. There is number of 
examples how to do this in nginx base: upstream_round_robin, 
upstream_ip_hash and in 3rd party modules: upstream_hash, upstream_fair, 
ngx_supervisord.

In short:
1) during configuration phase module sets pointer to init function in 
uscf->peer.init_upstream,
2) during initialization phase module sets pointer to per-request init 
function in uscf->peer.init and pointer to some data (which usually contains 
list of backend servers) in uscf->peer.data.
3) as each request is processed, function at uscf->peer.init is called and 
it, among other things, sets stuff like r->upstream->peer.get, 
r->upstream->peer.free and r->upstream->peer.tries.
4) before connecting to upstream server, function at r->upstream->peer.get 
is called and it sets information about which backend server nginx should 
connect to in (ngx_peer_connection_t *) pc,
5) after request is processed from the upstream, function at 
r->upstream->peer.free is called to "free resources".

That should be about it.

Best regards,
Piotr Sikora < piotr.sikora at frickle.com >




More information about the nginx-devel mailing list