title: What's the purpose of setting "X-Forwarded-For" header in nginx
body: <p>I have the following Nginx configuration for my Django application:</p>
  
  <pre><code>upstream api {
      server localhost:8000;
  }
  
  server {
      listen 80;
  
      location / {
          proxy_pass http://api;
          proxy_redirect off;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  
      location /staticfiles {
          alias /app/static/;
      }
  }
  </code></pre>
  
  <p>I based this config on a <a href="https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/#nginx" rel="nofollow noreferrer">tutorial here</a>. After some research, looks like setting the <code>Host</code> header allows the Django API to determine original client's IP address (instead of the IP address of the proxy).</p>
  
  <p>What's the point of the <code>X-Forwarded-For</code> header? I see a field called <code>$http_x_forwarded_for</code> in the nginx logs but I'm not sure it's related.</p>