set_local_today

The 'set_local_today' directive sets a local variable to today's date in a specified format and scope.

Syntaxset_local_today variable_name format_string;
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1

Description

The 'set_local_today' directive is used within NGINX configurations to assign a local variable that contains the current date formatted as a string. It is particularly useful in scenarios where you need to mark or log requests with today’s date, especially in dynamic content generation. The value assigned by 'set_local_today' is determined at the time of request processing, ensuring that it reflects the correct date according to the server's local time settings.

This directive expects one argument: the format specifier that indicates how the date should be formatted (for example, 'YYYY-MM-DD'). The directive can be placed in various contexts such as http, server, location, and within if blocks in these contexts, which allows for flexible use in different configurations. As a local variable, it is scoped to the request and will not affect or be visible to other requests being processed by the server.

In terms of usage, it is important for administrators to be aware of their server's time zone settings within the NGINX configuration to ensure the date returned by this directive is accurate. The format string closely follows the common strftime conventions, allowing for customization according to specific requirements or preferences.

Config Example

location /example {
    set_local_today $today "%Y-%m-%d";
    add_header X-Today $today;
}

Using incorrect format strings may lead to unexpected results or errors.

Ensure that the server's time zone is set correctly to get the accurate date.

Local variables are not accessible in other contexts, be sure to use them within the correct scope.

← Back to all directives