title: With Nginx, how do I preserve the client's IP address when using proxy_pass?
body: <p>I have a simple <code>proxy_pass</code> in NGINX that looks like this:</p>
  
  <pre><code>location / {
      proxy_pass https://foo.bar/API/;
      rewrite ^/API/(.*) /$1;
  }
  </code></pre>
  
  <p>When I print <code>$_SERVER["REMOTE_ADDR"];</code> (PHP) on the final destination (reached after the redirect) I see the server's IP instead of the client's IP.</p>
  
  <p>I tried to add </p>
  
  <pre><code>proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header REMOTE_ADDR $remote_addr;
  </code></pre>
  
  <p>to the <code>location /</code> in order to preserve the client's IP, but that doesn't work (I keep seeing the server's own IP).</p>
  
  <p>How can I preserve the client's IP after a <code>proxy_pass</code>?</p>