# Unique\_id

**URL:** <https://www.ruby-forum.com/t/unique-id/209586>\
**Category:** NGINX\
**Created:** [July 18, 2011, 11:07am UTC](https://www.ruby-forum.com/t/unique-id/209586 "2011-07-18T11:07:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [July 18, 2011, 11:07am UTC](https://www.ruby-forum.com/t/unique-id/209586/1 "2011-07-18T11:07:42Z")

</div>

hi,

i need something like  
[mod\_unique\_id - Apache HTTP Server Version 2.4](http://httpd.apache.org/docs/current/mod/mod_unique_id.html) (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](https://github.com/simpl/ngx_http_set_hash),  
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 🙂

thanks,  
gabor

---

<div class="post-metadata">

**Author:** ![SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/u/SSGSSbor_FarkasSS_S)\
**Post date:** [June 28, 2012, 11:55pm UTC](https://www.ruby-forum.com/t/unique-id/209586/2 "2012-06-28T23:55:21Z")

</div>

Resurrecting an old thread …

On 18 July 2011 10:07, Gábor Farkas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂 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

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/u/SSGSSbor_FarkasSS_S)\
**Post date:** [June 29, 2012, 8:00am UTC](https://www.ruby-forum.com/t/unique-id/209586/3 "2012-06-29T08:00:14Z")

</div>

[http://nginx.org/en/docs/http/ngx\_http\_userid\_module.html](http://nginx.org/en/docs/http/ngx_http_userid_module.html)

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@SSGSSbor\_FarkasSS\_S](https://www.ruby-forum.com/u/SSGSSbor_FarkasSS_S)\
**Post date:** [June 29, 2012, 3:07pm UTC](https://www.ruby-forum.com/t/unique-id/209586/4 "2012-06-29T15:07:59Z")

</div>

On 29 June 2012 06:59, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Module ngx\_http\_userid\_module](http://nginx.org/en/docs/http/ngx_http_userid_module.html)

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

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**
