Nginx clear X-Forwarded-For before setting

Solution 1:

Just don't use $proxy_add_x_forwarded_for - the whole purpose that it exists is to do the appending behavior.

Instead:

proxy_set_header X-Forwarded-For $remote_addr;

Solution 2:

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.

more_clear_input_headers "X-Forwarded-For";

see the docs from openresty: https://github.com/openresty/headers-more-nginx-module#more_clear_input_headers