$proxy_protocol_tlv_*

The $proxy_protocol_tlv_ variables provide access to information contained in the Proxy Protocol TLV (Type-Length-Value) format. — NGINX Core (HTTP)

$proxy_protocol_tlv_* NGINX Core (HTTP)

Description

The $proxy_protocol_tlv_ variables are prefixed variables in NGINX that allow for the retrieval of specific Type-Length-Value (TLV) data when using the Proxy Protocol. This protocol, which is often used in load balancing scenarios, transmits connection information (such as client IP addresses) from the proxy server to the backend server in a structured format. Each TLV data piece can be accessed using a suffix that identifies the specific information being requested. These variables are typically set when NGINX is configured to accept the Proxy Protocol from a direct client connection, such as when receiving traffic from a load balancer or proxy server that also implements this protocol. Common TLV types may include information such as client addresses, port numbers, and other header data. This added functionality enables backend servers to make more informed decisions based on client data that is not typically available due to NAT or other network setups that mask the true client IPs. For example, if a TLV item is specified with a suffix that corresponds to client address information, the variable will return the relevant information that was sent by the proxy. If no corresponding TLV data is provided by the upstream proxy server, the variable will be empty or unset. This behavior can be particularly useful in scenarios requiring accurate traffic logging or customization based on the originating client's details, enhancing the overall application performance and user experience.

Config Example

server {
    listen 80 proxy_protocol;

    location / {
        default_type text/plain;
        return 200 "Client IP: $proxy_protocol_tlv_client_ip\n";
    }
}

Subsystem

http

Cacheable

Yes

Type

Prefix variable

Contexts

http, server, location

Ensure that the Proxy Protocol is enabled on the upstream proxy to populate these variables; otherwise, the variables will be unset.

Misconfiguring the Proxy Protocol settings may lead to empty variable values, causing unintended application behavior or errors.