V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Recommended Services
Amazon Web Services
LeanCloud
New Relic
ClearDB
cst4you
V2EX  ›  云计算

Google Cloud Load Balancing + CDN 后获取真实 IP 的坑 (记录用)

  •  
  •   cst4you · 2016-05-31 12:33:52 +08:00 · 4300 次点击
    这是一个创建于 2848 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天在排查这个问题, 发现 Google 会在 X-Forwarded-For 头给你发来两个 IP, 分别是真实 IP 还有 Load Balancing 的外网 IP.

    在 Nginx 下, 配置了

    set_real_ip_from 130.211.0.0/22; // Google IP 
    real_ip_header X-Forwarded-For;
    

    之后发现获得的竟然是 Load Balancing 的外网 IP. 查了一些的资料, 加上这两行, 就可以正确获得 IP 了.

    set_real_ip_from (你的 Load Balancing 的外网 IP);
    real_ip_recursive on;
    
    5 条回复    2017-11-30 13:42:14 +08:00
    wenjianhn
        1
    wenjianhn  
       2016-06-01 18:12:33 +08:00
    这个不是坑吧。。。
    cst4you
        2
    cst4you  
    OP
       2016-06-01 19:18:00 +08:00
    @wenjianhn 只是我自己遇到的坑.
    canglaoshi
        3
    canglaoshi  
       2016-06-02 11:16:51 +08:00
    googlecdn 好用么。我是没配置成功过。
    cst4you
        4
    cst4you  
    OP
       2016-06-02 11:26:52 +08:00
    @canglaoshi 速度是可以的, 配置略繁琐(有 https 的情况下)
    will1916
        5
    will1916  
       2017-11-30 13:42:14 +08:00
    @cst4you 你好,请教 cdn 配置 https 的问题,可以 email 一下联系方式吗 gmail: aileen52000
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5841 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:38 · PVG 10:38 · LAX 19:38 · JFK 22:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.