set_secure_random_lcalpha

The `set_secure_random_lcalpha` directive generates a secure random string composed of lowercase alphabetic characters.

Syntaxset_secure_random_lcalpha variable [length];
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1-2

Description

The set_secure_random_lcalpha directive is part of the NGINX Set-Misc module, which provides additional capabilities for manipulating variables within NGINX configurations. When this directive is invoked, it generates a secure random string consisting exclusively of lowercase alphabetic characters (from 'a' to 'z'). This is beneficial for creating unique identifiers or tokens that require a degree of randomness while adhering to specific character constraints.

The directive accepts one or two arguments: the first argument is the variable that will hold the generated string, and the second (optional) argument specifies the length of the random string to be generated. If the length argument is not provided, a default length is applied, typically set to a standard value as defined by the module. With this feature, users can easily generate secure random values on-the-fly for use in HTTP headers, cookies, or other application-specific requirements, enhancing security and randomization in web applications.

To utilize this directive, it can be placed in various contexts such as 'http', 'server', 'location', and within conditional 'if' blocks. The flexibility in context allows for dynamic generation of random strings as required by the NGINX processing flow.

Config Example

http {
    server {
        location /random {
            set_secure_random_lcalpha $random_string 16;
            add_header X-Random-String $random_string;
        }
    }
}

Ensure the length value is a positive integer; exceeding practical limits may cause unexpected behavior.

Remember that each call generates a new string; the variable will change across requests if not otherwise controlled.

← Back to all directives