http-set-misc #

Adds string, URL, hash, hex, base32, base64 and time utility set_* directives to nginx variables — the rewrite-by-config Swiss-army knife OpenResty relies on.

Source: upstream source

Directives

set_base32_alphabet #

syntax: set_base32_alphabet 1 arg;  ·  context: http, server, location, server-if, location-if

The set_base32_alphabet directive (first introduced in v0.28) allows you to change the alphabet used for encoding/decoding so RFC-3548 compliant encoding is still possible by custom configurations.

set_base32_padding #

syntax: set_base32_padding on | off (on/off flag);  ·  context: http, server, location, server-if, location-if

But the padding behavior can be completely disabled by setting set_base32_padding off.

set_decode_base32 #

syntax: set_decode_base32 1 arg;  ·  context: http, server, location, server-if, location-if

Decodes a base32(hex)-encoded value from one variable into another.

set_encode_base32 #

syntax: set_encode_base32 1 arg;  ·  context: http, server, location, server-if, location-if

Encodes a source value into its base32(hex) digest and stores it in a variable.

set_formatted_gmt_time #

syntax: set_formatted_gmt_time 2 args;  ·  context: http, server, location, server-if, location-if

See also set_formatted_gmt_time. Back to TOC Caveats ======= Do not use $arg_PARAMETER, $cookie_COOKIE, $http_HEADER or other special variables defined in the Nginx core module as the target variable in this module's directives.

set_formatted_local_time #

syntax: set_formatted_local_time 2 args;  ·  context: http, server, location, server-if, location-if

See also set_formatted_local_time. Back to TOC set_formatted_local_time ------------------------ syntax: set_formatted_local_time $res <time-format> default: no context: location, location if phase: rewrite Set a formatted local time to variable $res (as the first argument) using the format string in the second argument.

set_hashed_upstream #

syntax: set_hashed_upstream 3 args;  ·  context: http, server, location, server-if, location-if

Hashes a source string to select a member from a named upstream list via modulo.

set_local_today #

syntax: set_local_today 1 arg;  ·  context: http, server, location, server-if, location-if

This directive was first introduced in the v0.22rc7 release. Back to TOC set_local_today --------------- syntax: set_local_today $dst default: no context: location, location if phase: rewrite Set today's date ("yyyy-mm-dd") in localtime to the argument variable $dst.

set_misc_base32_padding #

syntax: set_misc_base32_padding on | off (on/off flag);  ·  context: http, server, location, server-if, location-if

If you use earlier versions of this module, then you should use set_misc_base32_padding instead. Back to TOC set_misc_base32_padding ----------------------- syntax: set_misc_base32_padding on|off default: on context: http, server, server if, location, location if phase: no This directive has been deprecated since v0.28.

Example


 location /foo {
     set $a $arg_a;
     set_if_empty $a 56;

     # GET /foo?a=32 will yield $a == 32
     # while GET /foo and GET /foo?a= will
     # yeild $a == 56 here.
 }

 location /bar {
     set $foo "hello\n\n'\"\\";
     set_quote_sql_str $foo $foo; # for mysql

     # OR in-place editing:
     #   set_quote_sql_str $foo;

     # now $foo is: 'hello\n\n\'\"\\'
 }

 location /bar {
     set $foo "hello\n\n'\"\\";
     set_quote_pgsql_str $foo;  # for PostgreSQL

     # now $foo is: E'hello\n\n\'\"\\'
 }

 location /json {
     set $foo "hello\n\n'\"\\";
     set_quote_json_str $foo $foo;

     # OR in-place editing:
     #   set_quote_json_str $foo;

     # now $foo is: "hello\n\n'\"\\"
 }

 location /baz {
     set $foo "hello%20world";
     set_unescape_uri $foo $foo;

     # OR in-place editing:
     #   set_unescape_uri $foo;

     # now $foo is: hello world
 }

 upstream_list universe moon sun earth;
 upstream moon { ... }
 upstream sun { ... }
 upstream earth { ... }
 location /foo {
     set_hashed_upstream $backend universe $arg_id;
     drizzle_pass $backend; # used with ngx_drizzle
 }

 location /base32 {
     set $a 'abcde';
     set_encode_base32 $a;
     set_decode_base32 $b $a;

     # now $a == 'c5h66p35' and
     # $b == 'abcde'
 }

 location /base64 {
     set $a 'abcde';
     set_encode_base64 $a;
     set_decode_base64 $b $a;

     # now $a == 'YWJjZGU=' and
     # $b == 'abcde'
 }

 location /hex {
     set $a 'abcde';
     set_encode_hex $a;
     set_decode_hex $b $a;

     # now $a == '6162636465' and
     # $b == 'abcde'
 }

 # GET /sha1 yields the output
 #   aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
 location /sha1 {
     set_sha1 $a hello;
     echo $a;
 }

 # ditto
 location /sha1 {
     set $a hello;
     set_sha1 $a;
     echo $a;
 }

 # GET /today yields the date of today in local time using format 'yyyy-mm-dd'
 location /today {
     set_local_today $today;
     echo $today;
 }

 # GET /signature yields the hmac-sha-1 signature
 # given a secret and a string to sign
 # this example yields the base64 encoded singature which is
 # "HkADYytcoQQzqbjQX33k/ZBB/DQ="
 location /signature {
     set $secret_key 'secret-key';
     set $string_to_sign "some-string-to-sign";
     set_hmac_sha1 $signature $secret_key $string_to_sign;
     set_encode_base64 $signature $signature;
     echo $signature;
 }

 location = /rand {
…

↑ back to index