nginx – HttpGeoipModule $geoip_country_code为空

前端之家收集整理的这篇文章主要介绍了nginx – HttpGeoipModule $geoip_country_code为空前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Nginx.conf中:

http { 
    geoip_country /etc/Nginx/GeoIP.dat;
    ...
}

如果我做:

server{
    ...
    location / {
        add_header X-Geo $geoip_country_code;                   
        add_header X-Geo3 $geoip_country_code3;
        add_header X-IP $remote_addr;
        ...
    }
}

只有X-IP显示在我的标题中.

$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

如果我将位置块更改为:

location / {
    add_header X-Geo "foo";                   
    add_header X-Geo3 "bar";
    add_header X-IP $remote_addr;
    ...
}

标题显示,我如何获得$geoip_country_code?

最佳答案
我刚刚发现geo_ip有一个内部选项来使用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.
原文链接:https://www.f2er.com/nginx/435107.html

猜你在找的Nginx相关文章