<p>I’’m wondering “How to append Nginx IP to X-Forwarded-For”</p>

<p>I added snippet in Ingress annotation.</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ing
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header X-Forwarded-For "$remote_addr, $server_addr";
</code></pre>

<p>But it seems to double set in nginx.conf.</p>

<pre><code>    proxy_set_header X-Forwarded-For        $remote_addr;
...
    proxy_set_header X-Forwarded-For "$remote_addr, $server_addr";
</code></pre>

<p>So my backend server will get two <code>X-Forwarded-For</code></p>

<p>Anyone knows “How to disable the proxy_set_header part generated by Nginx Ingress Controller”?</p>

<pre><code>        proxy_set_header X-Request-ID           $req_id;
        proxy_set_header X-Real-IP              $remote_addr;

        proxy_set_header X-Forwarded-For        $remote_addr;

        proxy_set_header X-Forwarded-Host       $best_http_host;
        proxy_set_header X-Forwarded-Port       $pass_port;
        proxy_set_header X-Forwarded-Proto      $pass_access_scheme;

        proxy_set_header X-Scheme               $pass_access_scheme;
</code></pre>

RammusXu
<p>The accepted answer <strong>is not working</strong> for me. You just need to add the below <strong>annotation</strong> to the <strong>ingress</strong> object;</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers &quot;X-Forwarded-For $http_x_forwarded_for&quot;;
</code></pre>
<p><strong>for testing;</strong></p>
<pre><code>❯ curl -I https://example.com/path/here

HTTP/1.1 200 OK
cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Sat, 13 Mar 2021 08:52:02 GMT
expires: 0
pragma: no-cache
vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers
X-Forwarded-For: 88.888.8.8
Connection: keep-alive
</code></pre>
