Kubernetes nginx ingress redirects without path prefix

3/23/2021

I have a few apps that I am trying to get ingress set up for, the apps themselves will redirect to other urls for example:

app1host:8080/auth/logout?redirect_uri=/

I am trying to create a rule that allows the redirect to redirect back to my path but have not had any success.

app1host:8080/auth/logout?redirect_uri=/ -> domain.com/app1/auth/logout?redirect_uri=/

The current code redirects me back to the root folder domain.com/

kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
  name: nginx
  namespace: webservices
  uid: 96336c73-dcae-4c69-b1d3-0eacf8902173
  resourceVersion: '356090'
  generation: 63
  creationTimestamp: '2021-03-21T09:51:34Z'
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  managedFields:
    - manager: nginx-ingress-controller
      operation: Update
      apiVersion: networking.k8s.io/v1beta1
      time: '2021-03-21T14:19:21Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          f:loadBalancer:
            f:ingress: {}
    - manager: dashboard
      operation: Update
      apiVersion: networking.k8s.io/v1beta1
      time: '2021-03-23T22:51:34Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            f:nginx.ingress.kubernetes.io/app-root: {}
            f:nginx.ingress.kubernetes.io/rewrite-target: {}
    - manager: Mozilla
      operation: Update
      apiVersion: networking.k8s.io/v1beta1
      time: '2021-03-23T23:06:04Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:kubernetes.io/ingress.class: {}
        f:spec:
          f:rules: {}
spec:
  rules:
    - host: domain.com
      http:
        paths:
          - path: /app1(/|$)(.*)
            pathType: ImplementationSpecific
            backend:
              serviceName: app1
              servicePort: 8080
          - path: /app2(/|$)(.*)
            pathType: ImplementationSpecific
            backend:
              serviceName: app2
              servicePort: 8181
status:
  loadBalancer:
    ingress:
      - ip: 192.168.0.250
-- chemejon
kubernetes
nginx
nginx-ingress

2 Answers

3/24/2021

Have you tried using proxy-redirect-from and proxy-redirect-to:

nginx.ingress.kubernetes.io/proxy-redirect-from: "http://app1host:8080/"
nginx.ingress.kubernetes.io/proxy-redirect-to: "http://example.com/app1/"
-- Ertan Hasani
Source: StackOverflow

3/25/2021

I had to set the http root in the application it self, now it works as intended.

-- chemejon
Source: StackOverflow