Unique_id

hi,

i need something like
mod_unique_id - Apache HTTP Server Version 2.4 (but for
nginx obviously).

basically i need nginx to generate some kind of
uuid/checksum/something-unique, that it can send to an
upstream-proxied server,
and also put into the logs. the idea is to be able to track the
‘lifetime’ of a request as it traverses through nginx and into the
upstream server and then back into nginx.

currently i’m using an approach where i generate it in the
upstream-server, and then send it back to nginx in the response
as a header. and then i log it in nginx. this works fine when the
request finishes correctly, but when something crashes
in the upstream-server, and no response reaches nginx, there is no
uuid, so no uuid is written to the nginx logs. so, when
i start to investigate why things went wrong, i find the uuid in the
upstream-server logs, but i cannot match it to a line
in the nginx access logs.

any ideas?

the only thing i could find is to use something like
GitHub - vision5/ngx_http_set_hash: Nginx module that allows the setting of variables to the value of a variety of hashes,
and generate a hash from ip_address+timestamp+whatever, and send it to
upstream and log it,
but this means i have to recompile nginx, and still i’m not sure if it
will work or not :slight_smile:

thanks,
gabor

Resurrecting an old thread …

On 18 July 2011 10:07, Gábor Farkas [email protected] wrote:

‘lifetime’ of a request as it traverses through nginx and into the
upstream server and then back into nginx.

I had exactly this idea too :slight_smile: I’m wondering if anyone has any input?

Some random thoughts:

I’d like to avoid using embedded LUA/Perl/etc, even though they have
libraries that might do the actual (UU)ID generation. This is because,
as the OP suggests, having this header inserted at the most external
entry point to your network means you can track the request most
completely across your infrastructure. On my external nginx instances
(SSL-terminating, for example) I really like to keep the enabled
modules as light as possible to decrease the machine’s attack surface.

Linux exposes /proc/sys/kernel/random/uuid, which does the heavy
lifting for us of generating a (UU)ID. Windows … probably doesn’t
:-/

Is anyone doing anything like this? Am I missing a simple way of
achieving the goal of injecting (relatively) unique IDs into my N-tier
proxy_pass’d architecture?

Cheers!
Jonathan

Jonathan M.
Oxford, London, UK
http://www.jpluscplusm.com/contact.html

http://nginx.org/en/docs/http/ngx_http_userid_module.html


Igor S.

On 29 June 2012 06:59, Igor S. [email protected] wrote:

Module ngx_http_userid_module

Thanks for the pointer, Igor.
I can’t quite see how to use this to generate solely a new header to
add to the subsequent proxy_pass’d requests. I was /imagining/ that,
if I were get into the depths of actually writing a module, it’d
expose something like

proxy_set_header X-UUID $new_uuid;

I’m definitely /not/ looking to pass a cookie back to the consumer -
that’s not the aim at all, and wouldn’t work in my architecture.
Am I missing something obvious about how to use this module?

Jonathan

Jonathan M.
Oxford, London, UK
http://www.jpluscplusm.com/contact.html