Two new modules: random numbers and read cookies

Guy Naor guy at mor.ph
Wed Aug 20 06:54:30 MSD 2008


Hi,

I just wrote two nginx modules we needed for using nginx in our load 
balancing setup. Please have a look and give me feedback. I'd like to 
add them to the wiki, but would like some feedback before I do. I based 
them on existing modules as it was the easiest way to learn how to write 
an nginx module. I used mod_rewrite as the starting point.

The modules are:

1. mod-set-random
===============
This module adds a new command for the nginx configuration file: set_random

To use it: set_random $some_random_var;

This will cause every reference to $some_random_var to return a random 
number.
Please note that even in the same request different random numbers will be
return for each reference! The random number return is in the range of the
underlying OS rand() function.

I developed it to use in conjunction with the hash proxy module, to allow
client stickiness from initial request until the client session ends. 
See the README
for a full description and usage example.


2. mod-read-cookies
================
This module adds a new command for the nginx configuration file: 
set_from_cookie

To use it: set_from_cookie CookieName $some_var;

This will cause every reference to $some_var to return the value of the
cookie called CookieName. See the README for a full description and 
usage example.

Though there is already a mod-parsed-vars, it requires patching nginx. 
This module doesn't
require any patch to work.

Enjoy!

Guy Naor
CTO - Morph Labs
www.mor.ph



-------------- next part --------------
A non-text attachment was scrubbed...
Name: mod-read-cookies-0.1.tar.gz
Type: application/x-gzip
Size: 3184 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20080819/166fefb8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mod-set-random-0.1.tar.gz
Type: application/x-gzip
Size: 3283 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20080819/166fefb8/attachment-0001.bin>


More information about the nginx mailing list