Deploy a flask app with nginx + Gunicorn, and I need to get the real ip from visitors. (for Gunicorn can not get REMOTE-ADDR after nginx) I try to get client ip from X-Forwarede-for by this:
client_ip = request.headers.getlist("X-Forwarded-For")[0]
Sometimes I get client_ip correctly like this:
x-forwarded-for: 62.211.19.218
But sometimes I get client_ip wrong like this - combined with a proxy ip address (visit from some different Browsers):
x-forwarded-for: 62.211.19.218, 177.168.159.85
How to get only the first client ip (without the proxy address 177.168.159.85) when nginx forwards two ip addresses to App?