title: How to proxy_pass with nginx-ingress?
body: <p>I want to setup a k8s cluster, but I despair with the nginx-ingress controller and some special settings I need to set: especially proxy_pass.</p>
  
  <p>I tried to achieve that already with the "server-snippet"-snippet, but it didn't work.</p>
  
  <pre><code>apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
  kind: Ingress
  metadata:
      name: ingress
      annotations:
          nginx.ingress.kubernetes.io/rewrite-target: /$1
          nginx.ingress.kubernetes.io/affinity: "cookie"
          nginx.ingress.kubernetes.io/session-cookie-name: "route"
          nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
          nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
          nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
          nginx.ingress.kubernetes.io/ssl-redirect: "false"
          nginx.ingress.kubernetes.io/hsts: "false"
          nginx.ingress.kubernetes.io/server-snippet: |
              location / {
                  internal;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header X-Forwarded-Proto $scheme;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_buffering off;
  
                  proxy_pass http://localhost:30022/site/;
                  proxy_redirect default;
                  proxy_cookie_path /site/ /;
              }
  spec:
      rules:
          - host: preview.test.de
            http:
                paths:
                    - path: /
                      backend:
                          serviceName: backend-service
                          servicePort: 8080
  
  </code></pre>
  
  <p>What I want to achieve is this nginx config:</p>
  
  <pre><code>location / {
                  internal;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header X-Forwarded-Proto $scheme;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_buffering off;
  
                  proxy_pass http://localhost:30022/site/;
                  proxy_redirect default;
                  proxy_cookie_path /site/ /;
              }
  </code></pre>
  
  <p>In an optimal world I would like to achieve that the host and the port in the proxy_pass directive would be depend on the backend pod I want to connect to, so that there is no hard coded port.</p>
  
  <p>Can anyone help me out with this problem?</p>