AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 463971
Accepted
Kit Sunde
Kit Sunde
Asked: 2013-01-09 03:02:24 +0800 CST2013-01-09 03:02:24 +0800 CST 2013-01-09 03:02:24 +0800 CST

HttpGeoipModule $geoip_country_code 为空

  • 772

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

nginx
  • 4 4 个回答
  • 5668 Views

4 个回答

  • Voted
  1. Best Answer
    Tals
    2014-05-15T02:49:15+08:002014-05-15T02:49:15+08:00

    我刚刚发现 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.
    
    • 5
  2. Kit Sunde
    2013-01-18T22:05:22+08:002013-01-18T22:05:22+08:00

    啊,我只是弄清楚发生了什么。它试图为 LoadBalancers IP 而不是客户端解析 GeoIP,这就是为什么它是空白的。一旦我直接卷曲主机,它就返回了正确的结果。我必须使用 HttpRealipModule 为 HttpGeoipModule 提供客户端 IP。在我的会议中:

    real_ip_header X-Forwarded-For;
    set_real_ip_from 0.0.0.0/0;
    
    • 1
  3. slm
    2013-01-18T10:59:26+08:002013-01-18T10:59:26+08:00

    当您访问 / URL 时,您如何确认正在发送哪些标头?你能试试这个 curl 命令吗?

    与此类似但带有您的网址的内容:

    % curl -I www.google.com
    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=/; domain=.google.com
    Set-Cookie: NID=67=MBsS_mn5gvM2Zzt6Q6kfIO5h_brntWLnAmxZAXsNPseUgb5puv_8p8Io0ybgRqY62z0ihF-G5DLFtQOMN5MyIzM70IgPbkN4qOXKhCnQuUUqGCyuKkCg5XL6WfZoDR9m; expires=Fri, 19-Jul-2013 18:58:36 GMT; path=/; domain=.google.com; HttpOnly
    P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
    Server: gws
    X-XSS-Protection: 1; mode=block
    X-Frame-Options: SAMEORIGIN
    Transfer-Encoding: chunked
    
    • 0
  4. Hubert
    2017-08-01T17:12:58+08:002017-08-01T17:12:58+08:00

    或者,您可以在配置geoip块时指定 IP 源。注意:我只在 GeoIP2 上测试过

    geoip2 /etc/nginx/GeoIP/GeoLite2-Country.mmdb {
        $geoip2_data_country_code source=$http_x_forwarded_for country iso_code;
    }
    
    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve