In nginx.conf:
http {
geoip_country /etc/nginx/GeoIP.dat;
...
}
If I do:
server{
...
location / {
add_header X-Geo $geoip_country_code;
add_header X-Geo3 $geoip_country_code3;
add_header X-IP $remote_addr;
...
}
}
Only X-IP
show up in my headers.
$ curl -I www.example.org
HTTP/1.1 302 FOUND
Content-Type: text/html; charset=utf-8
Date: Thu, 17 Jan 2013 19:29:23 GMT
Location: http://www.example.org/login/?next=/
Server: nginx/1.2.2
Vary: Cookie
X-IP: 10.139.34.12
Connection: keep-alive
If I change the location block to:
location / {
add_header X-Geo "foo";
add_header X-Geo3 "bar";
add_header X-IP $remote_addr;
...
}
The headers show up, how can I get $geoip_country_code
?
I just found out the geo_ip has an internal option to use the
X-Forwarded-For
:Ah I just figure out what was happening. It was trying to resolve the GeoIP for the LoadBalancers IP rather than the client which is why it was blank. Once I curled the host directly, it returned the correct result. I had to use the HttpRealipModule to give the HttpGeoipModule the clients IP. In my conf:
How are you confirm what headers are being sent when you access the / URL? Can you try this curl command?
Something similar to this but with your URL:
Alternatively, you can specify your IP source when configuring your geoip block. Note: I have only tested this on GeoIP2