title: get Client IP in a flask based application
body: <p>I have Flask application deployed in server. and we are using Nginx. nginx setup is as below:</p>
  
  <pre><code>proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_read_timeout 25s;
  proxy_pass http://127.0.0.1:8000;
  add_header X-Cache $upstream_cache_status;
  </code></pre>
  
  <p>In Flask setup I have done the following :</p>
  
  <pre><code>app = Flask(__name__, static_folder=None)
  app.wsgi_app = ProxyFix(app.wsgi_app)
  </code></pre>
  
  <p>Now, whenever user visits a site, I want a real ip. Currently I am getting </p>
  
  <blockquote>
    <p>127.0.0.1</p>
  </blockquote>
  
  <p>I have tried like below:</p>
  
  <pre><code>if request.headers.getlist("X-Forwarded-For"):
      ip = request.environ['HTTP_X_FORWARDED_FOR']
  else:
      ip = request.remote_addr
  </code></pre>
  
  <p>Could anybody guide me here please.</p>