set_md5

The `set_md5` directive computes the MD5 hash of a specified variable value in NGINX.

Syntaxset_md5 $var_name value | $another_var_name;
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1-2

Description

The set_md5 directive is part of the NGINX Set-Misc module and is used to generate an MD5 hash from a given value. This directive requires one or two arguments; the first is the variable name that will contain the result, and the second is the value to be hashed or another variable to be hashed. If only one argument is provided, it defaults to hashing the value of the specified variable. The result can then be referenced in other parts of NGINX configuration, making it useful for tasks such as caching, security, or creating unique identifiers based on variable content.

Internally, the directive utilizes the MD5 hashing algorithm which is implemented in the NGINX source code, allowing for efficient computation of the hash. This is useful for scenarios where data integrity or quick comparisons are necessary. Additionally, since MD5 is widely recognized, its use in computing unique keys for caching or other operational needs tends to integrate well within broader systems designed to work with hashed values. The computed hash is always stored as a string, making it easy to use in contexts where string operations or checks are necessary.

Config Example

location /example {
    set $my_value "Hello, World!";
    set_md5 $my_hash $my_value;
    # Now $my_hash contains the MD5 hash of "Hello, World!"
}

Ensure that the input value is not null; otherwise, the result will also be null.

Remember that MD5 is not a cryptographic security measure and is not suited for use in contexts requiring strong security. Use it primarily for hashing and not for encrypting sensitive information.

← Back to all directives