$proxy_protocol_addr
$proxy_protocol_addr returns the client address from the PROXY protocol, if enabled. — NGINX Core (HTTP)
Description
The variable $proxy_protocol_addr is part of NGINX's support for the PROXY protocol, which allows passing the original client IP address through a proxy server. When a client connects to an NGINX server that has proxy protocol support enabled, NGINX can parse the PROXY protocol header sent by the proxy and extract the original client address. This enables NGINX to correctly log requests with the client's actual IP address instead of the proxy's IP address, which would otherwise be logged. This variable is typically used in configurations where NGINX is set up behind load balancers or reverse proxies that implement the PROXY protocol. The variable is populated only when the incoming connection has a corresponding PROXY protocol header; under other circumstances, it will typically return an empty value. Clients that connect directly to NGINX will not benefit from this variable, and it will reveal the IP of the last proxy instead. Commonly, it will contain either an IPv4 or IPv6 address, depending on the client's connection type.
Config Example
server {
listen 80 proxy_protocol;
location / {
proxy_pass http://backend;
add_header X-Real-IP $proxy_protocol_addr;
}
}Subsystem
httpCacheable
YesContexts
http, server, location, ifEnsure that the PROXY protocol is enabled on both the NGINX server and the upstream proxy.
If the incoming connection does not include a PROXY protocol header, this variable will be empty.
Make sure that only trusted proxies are allowed to connect with proxy protocol to avoid spoofing.