$proxy_protocol_server_addr
$proxy_protocol_server_addr returns the IP address of the client as sent by the proxy protocol when enabled in NGINX. — NGINX Core (HTTP)
Description
The variable $proxy_protocol_server_addr is primarily used in configurations involving proxy protocol, which is a feature that allows NGINX to receive the original client IP address and port when serving requests proxied through another layer (like AWS ELB or other reverse proxies). This variable is populated when the proxy protocol is enabled on the server or location block using the 'proxy_protocol' directive. Its value reflects the IP address of the client as decoded from the proxy protocol header, making it essential for accurate logging or access control based on the actual client address rather than the address of the immediate proxy. When this variable is set, it can significantly improve the accuracy of metrics and logs, as you can track actual client addresses instead of the IP address of the reverse proxy. If proxy protocol is not in use or if it is not properly set up, the value of $proxy_protocol_server_addr will be an empty string. As such, it is common to see this variable utilized in combination with other proxy variables to ensure the original client’s information is correctly captured.
Config Example
server {
listen 80 proxy_protocol;
location / {
access_log /var/log/nginx/access.log '$proxy_protocol_server_addr';
}
}Subsystem
httpCacheable
YesContexts
http, server, locationEnsure the proxy protocol is explicitly enabled; otherwise, this variable will not be populated.
Misconfiguration of the upstream proxy can lead to empty or incorrect values.
If running behind multiple layers of proxies, ensure that the correct proxy protocol headers are retained.