Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In nginx.conf:

http { 
    geoip_country /etc/nginx/GeoIP.dat;

If I do:

    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
HTTP/1.1 302 FOUND
Content-Type: text/html; charset=utf-8
Date: Thu, 17 Jan 2013 19:29:23 GMT
Server: nginx/1.2.2
Vary: Cookie
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?

share|improve this question
Please post your other location blocks. – Michael Hampton Jan 17 '13 at 19:36
up vote 3 down vote accepted

I just found out the geo_ip has an internal option to use the X-Forwarded-For:

syntax: geoip_proxy address | CIDR;
default:     —
context:    http
This directive appeared in versions 1.3.0 and 1.2.1.
Defines trusted addresses. When a request comes from a trusted address, an address from the “X-Forwarded-For” request header field will be used instead.
share|improve this answer

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:

real_ip_header X-Forwarded-For;
share|improve this answer

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:

% curl -I
HTTP/1.1 200 OK
Date: Thu, 17 Jan 2013 18:58:36 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=39403a60450f4bb3:FF=0:TM=1358449116:LM=1358449116:S=uoBAz3VFZpjyc1hA; expires=Sat, 17-Jan-2015 18:58:36 GMT; path=/;
Set-Cookie: NID=67=MBsS_mn5gvM2Zzt6Q6kfIO5h_brntWLnAmxZAXsNPseUgb5puv_8p8Io0ybgRqY62z0ihF-G5DLFtQOMN5MyIzM70IgPbkN4qOXKhCnQuUUqGCyuKkCg5XL6WfZoDR9m; expires=Fri, 19-Jul-2013 18:58:36 GMT; path=/;; HttpOnly
P3P: CP="This is not a P3P policy! See for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
share|improve this answer
I've edited the question and included the curl response. I was confirming it with curl and chromes developer toolbar. – Kit Sunde Jan 17 '13 at 19:29
If you set the headers with static strings do they still not show up? – slm Jan 17 '13 at 19:30
@sim They do, just tried it. – Kit Sunde Jan 18 '13 at 6:00
So is the issue something with those variable values getting set then? – slm Jan 18 '13 at 7:01
Turns out the issue was that it was grabbing the IP of the LoadBalancer to do the matching, which didn't match anything and then left the variables blank which didn't push out the headers. – Kit Sunde Jan 18 '13 at 7:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.