Darren O'Brien
Darren O'Brien

Reputation: 1

Lighttpd equivalent of Apache's mod_unique_id

I'm migrating from Apache on EC2 instances to Lighttpd in containers and one of the pieces of functionality that's missing is the ability to generate a unique id for each request that can be passed on to the PHP application for tracing. We currently use Apache's mod_unique_id for this.

I searched for an equivalent module in Lighttpd and read the Lighttpd configuration reference to see if a UUID could be generated by any means but I didn't find a way to do it.

Does anyone know how this might be achieved in Lighttpd or could it be done by scripting something using CGI?

Thanks.

Upvotes: 0

Views: 52

Answers (1)

gstrauss
gstrauss

Reputation: 2404

lighttpd mod_magnet and lua mod_usertrack or anything else you want to do with a few lines of lua.

A lua script with the following is probably sufficient for simple uses of UNIQUE_ID:

lighty.r.req_env["UNIQUE_ID"] = lighty.c.b64urlenc(lighty.c.rand())
return 0

If you needed to increase the length of the unique id, you could prepend a timestamp lighty.c.time() or a high-resolution timestamp lighty.c.hrtime(), or for something nearly equivalent to UUIDv4, you could concatenate four (4) calls to lighty.c.rand()

Another example

local r = lighty.r
local c = lighty.c
r.req_env["UNIQUE_ID"] = c.md("sha256", tostring(c.time())
                                     .. r.req_attr["request.remote-addr"]
                                     .. tostring(c.rand()))
return 0

Another edit: I added lua mod_unique_id to the lighttpd wiki.

Upvotes: 1

Related Questions