Nginx Embedded Variables 嵌入式变量解析(5)
相关链接
一、目录
1.1 指令目录
1.1.30 ngx_stream_ssl_module
1.1.31 ngx_stream_ssl_preread_module
1.1.32 ngx_stream_upstream_module
- $upstream_addr
- $upstream_bytes_received
- $upstream_bytes_sent
- $upstream_connect_time
- $upstream_first_byte_time
- $upstream_session_time
1.1.33 ngx_otel_module
二、解释
2.30 ngx_stream_ssl_module
2.30.1 变量列表
$ssl_alpn_protocol
$ssl_cipher
$ssl_ciphers
$ssl_client_cert
$ssl_client_fingerprint
$ssl_client_i_dn
$ssl_client_raw_cert
$ssl_client_s_dn
$ssl_client_serial
$ssl_client_v_end
$ssl_client_v_remain
$ssl_client_v_start
$ssl_client_verify
$ssl_curve
$ssl_curves
$ssl_protocol
$ssl_session_id
$ssl_session_reused
2.31 ngx_stream_ssl_preread_module
2.31.1 变量列表
$ssl_preread_alpn_protocols
功能:返回客户端通过ALPN广告的协议列表。
描述:表示客户端通过ALPN(Application-Layer Protocol Negotiation)扩展广告的协议列表。自Nginx版本1.13.10起可用。协议值以逗号分隔。
示例:
stream {
upstream backend {
server backend1.example.com:12345;
}
server {
listen 12345;
ssl_preread on;
proxy_pass backend;
log_format ssl_preread '$remote_addr - $remote_user [$time_local] "$ssl_preread_alpn_protocols"';
}
}
在这个例子中,日志会记录客户端通过ALPN广告的协议列表。
$ssl_preread_protocol
功能:返回客户端支持的最高SSL协议版本。
描述:表示客户端支持的最高SSL/TLS协议版本。自Nginx版本1.15.2起可用。这个变量通常用于在SSL握手之前读取客户端信息(例如,在TCP层)。
示例:
stream {
upstream backend {
server backend1.example.com:12345;
}
server {
listen 12345;
ssl_preread on;
proxy_pass backend;
log_format ssl_preread '$remote_addr - $remote_user [$time_local] "$ssl_preread_protocol"';
}
}
在这个例子中,日志会记录客户端支持的最高SSL协议版本。
$ssl_preread_server_name
功能:返回通过SNI请求的服务器名称。
描述:表示客户端通过SNI(Server Name Indication)扩展请求的服务器名称。自Nginx版本1.11.0起可用。此变量通常用于在SSL握手之前读取SNI信息。
示例:
stream {
upstream backend {
server backend1.example.com:12345;
}
server {
listen 12345;
ssl_preread on;
proxy_pass backend;
log_format ssl_preread '$remote_addr - $remote_user [$time_local] "$ssl_preread_server_name"';
}
}
在这个例子中,日志会记录客户端通过SNI请求的服务器名称。
2.32 ngx_stream_upstream_module
2.32.1 变量列表
$upstream_addr
$upstream_bytes_received
$upstream_bytes_sent
$upstream_connect_time
$upstream_first_byte_time
功能:返回接收上游响应第一个字节所需的时间。
描述:表示从发送请求到接收到上游服务器响应的第一个字节所花费的时间。时间以秒为单位,并精确到毫秒。多个连接的时间用逗号分隔,类似于$upstream_addr变量中的地址。自Nginx版本1.11.4起可用。
示例:
location /api {
proxy_pass http://backend_servers;
log_format timing '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$upstream_first_byte_time"';
}
在这个例子中,日志会记录接收上游响应第一个字节所需的时间。
$upstream_session_time
功能:返回与上游服务器会话的持续时间。
描述:表示与上游服务器会话的总持续时间,以秒为单位,并精确到毫秒。多个连接的时间用逗号分隔,类似于$upstream_addr变量中的地址。自Nginx版本1.11.4起可用。
示例:
location /api {
proxy_pass http://backend_servers;
log_format timing '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$upstream_session_time"';
}
在这个例子中,日志会记录与上游服务器会话的总持续时间。
2.33 ngx_otel_module
2.33.1 变量列表
$otel_parent_id
功能:父跨度的标识符。
描述:提供当前请求的父跨度ID。如果当前请求是由另一个请求触发的,则会有一个父跨度ID来标识那个父请求。例如,dc94d281b0f884ea。
示例:
log_format otel_parent '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$otel_parent_id"';
access_log /var/log/nginx/otel_parent.log otel_parent;
$otel_parent_sampled
功能:父跨度的“采样”标志,可以是“1”或“0”。
描述:表示父跨度是否被采样。值为“1”表示父跨度被采样,值为“0”表示未被采样。这对于决定是否需要记录详细的追踪信息非常有用。
示例:
log_format otel_sampling '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$otel_parent_sampled"';
access_log /var/log/nginx/otel_sampling.log otel_sampling;
$otel_span_id
功能:当前跨度的标识符。
描述:提供当前请求的跨度ID。每个请求在分布式追踪系统中都有一个唯一的跨度ID,用于标识该请求中的特定操作或步骤。例如,4c0b8531ec38ca59。
示例:
log_format otel_span '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$otel_span_id"';
access_log /var/log/nginx/otel_span.log otel_span;
$otel_trace_id
功能:当前跨度所属跟踪的标识符。
描述:提供当前请求所归属的跟踪ID。这对于分布式追踪系统中识别和关联多个相关请求非常有用。例如,56552bc4daa3bf39c08362527e1dd6c4。
示例:
log_format otel_trace '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$otel_trace_id"';
access_log /var/log/nginx/otel_trace.log otel_trace;

被折叠的 条评论
为什么被折叠?



