Google Cloud Load Balancing + CDN 后获取真实 IP 的坑 (记录用)
今天在排查这个问题, 发现 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;
本文由 vps网友提供,转载请注明出处
本文链接: https://www.vpsvsvps.com/discuss/a/1676471770275647488.html