$time_local

The $time_local variable returns the current local time in the format used by the Common Log Format. — NGINX Core (HTTP)

$time_local NGINX Core (HTTP)

Description

The $time_local variable in NGINX provides the local server time when a request is received. It is formatted as 'day/month/year:hour:minute:second zone', following the Common Log Format, which is universally recognized for log entries. This variable is particularly useful for logging purposes, allowing administrators to track when requests are made based on the timezone settings of the server. The value of $time_local is set during the request processing phase, specifically when a request is received in the application. As such, it ensures that the time stamp corresponds accurately to the moment a request is processed. By default, this variable is formatted according to the server's local timezone, which can be specified using directives in the NGINX configuration. Typical values of this variable might look like '12/Apr/2023:18:30:12 +0300', indicating the exact date and time along with the timezone offset. Given its importance in logging, it is often used in custom log formats to capture the requested timestamps precisely, thus allowing for easier troubleshooting and monitoring of server activity.

Config Example

log_format my_log_format '$remote_addr - $remote_user [$time_local] "$request"';

access_log /var/log/nginx/access.log my_log_format;

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Ensure the server's timezone is correctly set; otherwise, $time_local may not reflect the expected local time.

When using in custom log formats, make sure the log format string is correctly quoted to avoid syntax errors.