Nginx Ingress Controller does not set X-Forwarded-Host

6/25/2019

I have setup the Nginx Ingress Controller with my microservice; this microservice uses Hateoas to produce the links; I have the following Ingress set.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "server: imemywork";
    nginx.org/ssl-services: "mic-ser-service"
    nginx.org/client-max-body-size: "1024m"
    nginx.ingress.kubernetes.io/server-snippet: |
      location /service(|/)(.*) {
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Host  $host/service;
        proxy_set_header X-Forwarded-Port  $server_port;
      }
  name: mic-ser-ingress
spec:
  tls:
    - hosts:
      - imemywork.com
      secretName: mic-ser-tls-certificate
  rules:
    - host: api.imemywork.com
      http:
        paths:
        - path: /service(|/)(.*)
          backend:
            serviceName: mic-ser-service
            servicePort: 8080

None of X-Forwarded-* headers get set on the request; Since these are not set, the HATEOAS links are using http and the host sent by browser to produce links; Am I setting them in wrong place? I also tried to move the location block to under configuration-snippet with no luck; Is there anything else, I need to set/enable in Nginx Ingress controller?

Bts, having more_set_header under configuration-snippet only adds the headers to the response, not on the request to the server.

-- Tech Junkie
kubernetes-ingress
nginx
nginx-ingress

0 Answers