What can I use in the nginx config to make it clear any existing X-Forwarded-For headers before setting its own? I am currently using Nginx to terminate SSL before passing traffic to HAProxy to load balance.
Right now, I have:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
This will append a new IP address to the end of any existing X-Forwarded-For IP addresses however. Is there a way to only keep the address seen by Nginx?
Just don't use
$proxy_add_x_forwarded_for
- the whole purpose that it exists is to do the appending behavior.Instead:
If anyone still have this issue, you can make use of "more_clear_input_headers" to keep only the address of last hop seen by Nginx.
see the docs from openresty: https://github.com/openresty/headers-more-nginx-module#more_clear_input_headers