$connection_time
The $connection_time variable returns the time taken to establish a connection to the client, in seconds. — NGINX Core (HTTP)
Description
The $connection_time variable in NGINX captures the duration, in seconds, it takes to establish a connection to a client after NGINX has received the request. This value is determined at the time the connection is established, enabling the measurement of latency from the perspective of the NGINX server. The variable is updated as part of the connection processing flow and is primarily suitable for logging or metrics collection associated with connection times. Common values might range from fractions of a second in optimal conditions to multiple seconds in scenarios with high latencies or connection issues. The context of when $connection_time is set starts as soon as the NGINX worker process accepts a new connection from a client, which corresponds to the moment the request begins to be processed. Developers and administrators can use this variable to gain insights into performance characteristics, especially when monitoring the behavior of the web server under various network conditions or loads. Analyzing these values can help in deducing the health of the server and identifying potential performance bottlenecks related to client connections.
Config Example
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' \
'$status $body_bytes_sent "$http_referer" ' \
'"$http_user_agent" "$http_x_forwarded_for" ' \
'Connection time: $connection_time';
access_log /var/log/nginx/access.log main;Subsystem
httpCacheable
NoContexts
http, server, location, ifThe value of $connection_time is only set for accepted connections; it does not account for any processing time after the connection is established.
In scenarios where proxying occurs, ensure that connection time metrics are interpreted correctly, as they may not represent the client-to-server connection time accurately.