<p>I'm using ingress for kubernetes. My ingress is kubernetes nginx ingress. And  routing configs don't work and redirect me root path in every request in https section All configs is given below </p>

<pre><code>cat frontapi-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: swagger-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: preprod-ops.kblab.local
    http:
      paths:
      - backend:
          serviceName: kb-workplace
          servicePort: 8080
        path: /
      - backend:
          serviceName: gw-branch
          servicePort: 8443
        path: /api
$ cat swagger-portal.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: swagger-portal
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: preprod-ops.kblab.local
    http:
      paths:
      - backend:
          serviceName: swagger-portal
          servicePort: 9001
        path: /swagger-portal
</code></pre>

<p>Above config <strong>works properly with http config</strong> but, below config <strong>doesn't work with https config. It only</strong> works swagger-portal section</p>

<pre><code>$cat frontapi-ingress-https.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/secure-verify-ca-secret: preprod.kblab.local
    kubernetes.io/ingress.class: nginx
  generation: 1
  name: app-ingress
spec:
  rules:
  - host: preprod.kblab.local
    http:
      paths:
      - backend:
          serviceName: gw-branch
          servicePort: 8443
        path: /api
      - backend:
          serviceName: kb-workplace
          servicePort: 8080
        path: /
      - backend:
          serviceName: acs-alfresco
          servicePort: 8080
        path: /acs
  tls:
  - hosts:
    - preprod.kblab.local
  - secretName: preprod.kblab.local

$ cat swagger-portal-https.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: swagger-portal
spec:
  rules:
  - host: preprod.kblab.local
    http:
      paths:
      - backend:
          serviceName: swagger-portal
          servicePort: 9001
        path: /swagger-portal/a
  tls:
  - hosts:
    - preprod.kblab.local
  - secretName: preprod.kblab.local
</code></pre>

<p>Thanks in advance.</p>

Babak Mammadov
<p>You are setting the <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer"><code>nginx.ingress.kubernetes.io/rewrite-target: /</code></a> annotation on your <code>swagger-portal-https.yaml</code> Ingress, which explicitly implies the redirection to the root path.</p>

<p>If you want to preserve the request path, you need to remove this annotation.</p>
