我想獲取真實ip我正在使用cloudflare和Google Cloud Network Load Balancer。從Google Cloud Load Balancer和cloudflare獲取真實ip
我已經把這個源nginx.conf
# Last updated Sat Jul 30 11:17:32 UTC 2016
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 130.211.0.0/22; #Google IP
real_ip_header X-Forwarded-For; #CF-Connecting-IP;
要檢查我的IP,我做了簡單的Rails源。
return render :json => {:ip => request.ip, :remote_ip => request.remote_ip, :x_forwarded_for => request.env['HTTP_X_FORWARDED_FOR'], :client_ip => request.env['HTTP_CLIENT_IP'], :cf => request.env['CF-Connecting-IP']}
。
{"ip":"130.211.0.145","remote_ip":"130.211.0.145","x_forwarded_for":"(REAL IP), 141.101.85.141, 130.211.16.204, 130.211.0.145","client_ip":null,"cf":null}
但ip不是我的ip,它是Google Cloud LoadBalancer的。我該如何解決這個問題?我在6個小時內嘗試了很多時間。
謝謝。
如果你使用多個代理,你應該在''''上設置'''real_ip_recursive'。 – ryush00