How to set random value in the specified range in variable without 3rd party modules in nginx's config?
Something like
set $random_value rand(1,4);
using macports:
afte reading those https://trac.macports.org/ticket/19342 https://stackoverflow.com/questions/7812596/installing-nginx-via-macports-with-ngx-echo-module-available
(has to be perl 5.8 or 5.10)
# port -f install perl5 +perl5_8
# port clean nginx
# port install nginx +perl5
I cant post more links, find the /HttpEchoModule#Installation on the nginx site
cd /opt/local/src/
download the tgz here: https://github.com/agentzh/echo-nginx-module/downloads tar -zxvf /Users/lorieri/Downloads/agentzh-echo-nginx-module-v0.37rc7-1-gb0e0a23.tar.gz
port edit nginx
add those lines, between any other variant
variant echo description {Add echo } {
configure.args-append --add-module=/opt/local/src/agentzh-echo-nginx-module-b0e0a23
}
then...
# port install -v nginx +perl5 +echo
edit /opt/local/etc/nginx and mention in the previous (below) comment, in the http context then edit same file to add test location
location /lorieri {
default_type text/plain;
echo $rnd;
}
run nginx
# nginx
test it with curl, wget, your browser...
# curl localhost/lorieri
9
# curl localhost/lorieri
8
# curl localhost/lorieri
8
# curl localhost/lorieri
9
# curl localhost/lorieri
6
why I did that ? to set on nginx a cookie user_uid for a year and a random cookie for the current session
http {
perl_set $rnd 'sub { return int(rand(10 - 5)) + 5; }';
...
}
Using perl module.
And what is the goal of such caching?
fastcgi_cache_key "$request_method|$host|$request_uri|$random_value";