geoip2_proxy_recursive
The geoip2_proxy_recursive directive is used in the NGINX GeoIP2 module to determine whether to use the last non-trusted address from the X-Forwarded-For header instead of the original client address when recursive search is enabled. This is useful when you want to accurately identify the client's IP address in a chain of proxy servers.
Syntax
geoip2_proxy_recursive on | off;
Example
load_module modules/ngx_http_geoip2_module.so;
http {
geoip2 /etc/maxmind-country.mmdb {
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
}
geoip2_proxy 192.168.0.0/16;
geoip2_proxy_recursive on;
server {
listen 80;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Use the GeoIP2 data
add_header X-Country-Code $geoip2_data_country_code;
}
}
}
In this configuration, the geoip2_proxy_recursive on; directive ensures that the last non-trusted IP address from the X-Forwarded-For header is used for GeoIP lookups, allowing for more accurate client location data when requests pass through multiple proxies.