加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx – HttpGeoipModule $geoip_country_code为空

发布时间:2020-12-13 21:08:57 所属栏目:Nginx 来源:网络整理
导读:在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显示在我的标题

在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读