0
votes

Ip have request flows through 3 nginx proxy, and ip got the x-forwarded-for list ip of :

192.168.10.222, 192.168.10.178, 192.168.10.179

how can I get the first ip using map module ? I've found this but can't make it working:

map $proxy_add_x_forwarded_for $client_ip {

"~(?<IP>([0-9]{1,3}\.){3}[0-9]{1,3}),.*" $IP;

}

from here: https://webkul.com/blog/x-forwarded-for-header-in-nginx-containing-mulitple-client-ips

Thanks

1
Do you want to read x-forwared-for or you want to write x-forwared-for with the client ip ? - flaixman
@flaixman currently read is enough - NOZUONOHIGH

1 Answers

1
votes

Thats what you are looking for:

map $proxy_add_x_forwarded_for $client_ip {"~(?<IP>([0-9]{1,3}\.){3}[0-9]{1,3}),.*" $IP;}

It will map the first ip of the 3 to the variable $client_ip. As one line out of the server and location scope.