<p>I have a Django application hosted on Apache inside a Kubernetes cluster running as a deployment. The application is running on port 8080 and app root is <em>&quot;/&quot;</em>. I want my ingress to redirect to my application when someone enters /tascaty but this is not happening when I enter the path as /tascaty in ingress resource. But when I set path as / it works. Below are the details of my APP</p>
<p>Apache Config File for application:</p>
<pre class="lang-html prettyprint-override"><code>Listen 8080
&lt;VirtualHost *:8080&gt;

        WSGIDaemonProcess tascaty_dev python-path=/usr/local/lib/python3.8/dist-packages

        &lt;Location /&gt;
                WSGIProcessGroup tascaty_dev
                WSGIApplicationGroup %{GLOBAL}
        &lt;/Location&gt;

        WSGIScriptAlias / /usr/local/lib/python3.8/dist-packages/tascaty_project/wsgi.py
        &lt;Directory /usr/local/lib/python3.8/dist-packages/tascaty_project/&gt;
                &lt;Files wsgi.py&gt;
                        Require all granted
                &lt;/Files&gt;
        &lt;/Directory&gt;

        Alias /static /usr/local/lib/python3.8/dist-packages/static
        &lt;Directory /usr/local/lib/python3.8/dist-packages/static&gt;
                Require all granted
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</code></pre>
<p>App Deployment :</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tascatyk8s-deployment
  namespace: tascaty
spec:
  replicas: 1
  selector:
    matchLabels:
      component: tascatyk8s
  template:
    metadata:
      labels:
        component: tascatyk8s
    spec:
      volumes:
        - name: tascatyk8s-mount
          persistentVolumeClaim:
            claimName: tascatyk8s-pvc
      containers:
        - name: tascatyk8s
          image: abdul8423/tascatyk8s:v3
          ports:
            - containerPort: 8080
          volumeMounts:
            - mountPath: /usr/local/lib/python3.8/dist-packages/users/migrations
              name: tascatyk8s-mount
              subPath: users
            - mountPath: /usr/local/lib/python3.8/dist-packages/tascaty/migrations
              name: tascatyk8s-mount
              subPath: tascaty
            - mountPath: /usr/local/lib/python3.8/dist-packages/leaves/migrations
              name: tascatyk8s-mount
              subPath: leaves
            - mountPath: /usr/local/lib/python3.8/dist-packages/blog/migrations
              name: tascatyk8s-mount
              subPath: blog
          env:
            - name: TASCATY_HOST
              valueFrom:
                configMapKeyRef:
                  name: tascatyk8s-dep-configmap
                  key: TASCATY_HOST
            - name: TASCATY_PORT
              valueFrom:
                configMapKeyRef:
                  name: tascatyk8s-dep-configmap
                  key: TASCATY_PORT
            - name: TASCATY_DB
              valueFrom:
                configMapKeyRef:
                  name: tascatyk8s-dep-configmap
                  key: TASCATY_DB
            - name: TASCATY_USER
              valueFrom:
                configMapKeyRef:
                  name: tascatyk8s-dep-configmap
                  key: TASCATY_USER
            - name: TASCATY_PASS
              valueFrom: 
                secretKeyRef:
                  name: tascaty-secret
                  key: MYSQL_PASSWORD
      nodeSelector:
        component: tascaty
</code></pre>
<p>App Service</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: tascatyk8s-cluster-ip-service
  namespace: tascaty
spec:
  type: ClusterIP
  selector:
    component: tascatyk8s
  ports:
    - port: 8080
      targetPort: 8080
</code></pre>
<p>Ingress Controller is installed using</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/baremetal/deploy.yaml
</code></pre>
<p>Ingress Resource :</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: tascatyk8s-deployment-ingress
  namespace: tascaty
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /tascaty
        backend:
          serviceName: tascatyk8s-cluster-ip-service
          servicePort: 8080
</code></pre>
<p>When I try to access <a href="https://192.168.56.2:31150/tascaty" rel="nofollow noreferrer">https://192.168.56.2:31150/tascaty</a> it redirects to <a href="https://192.168.56.2:31150/login/?next=/" rel="nofollow noreferrer">https://192.168.56.2:31150/login/?next=/</a>
but I get a <em><code>404 Not Found</code></em></p>
<p><img src="https://i.stack.imgur.com/Xe8cu.png" alt="image1" /></p>
<p>But when I replace the path inside the ingress resource with / instead of /tascaty it works fine.</p>

<h3>What's happening with the ingress path <em><code>/tascaty</code></em>:</h3>
<p>Your Apache/WSGI server is doing the redirect. After the redirect to <code>/</code>, the client goes back to the ingress and the ingress doesn't know how to handle that so it will show you a <em><code>404</code></em></p>
<h3>What's happening with the ingress path <em><code>/</code></em>:</h3>
<p>Your Apache/WSGI server is doing the redirect. After the redirect to <code>/</code>, the client goes back to the ingress and the ingress knows how to handle <code>/</code> and it all works great.</p>
<p>So both your ingress (which is running nginx) and Apache need to agree on the same path all the time. So you either use <em><code>/</code></em> on your ingress or you change your Apache configuration to also serve on <em><code>/tascaty</code></em> so that instead of redirecting to <em><code>/</code></em> it redirects to <em><code>/tascaty</code></em>.</p>
<p>Example of the latter:</p>
<pre class="lang-html prettyprint-override"><code>Listen 8080
&lt;VirtualHost *:8080&gt;

        WSGIDaemonProcess tascaty_dev python-path=/usr/local/lib/python3.8/dist-packages

        &lt;Location /tascaty&gt;
                WSGIProcessGroup tascaty_dev
                WSGIApplicationGroup %{GLOBAL}
        &lt;/Location&gt;

        WSGIScriptAlias /tascaty /usr/local/lib/python3.8/dist-packages/tascaty_project/wsgi.py
        &lt;Directory /usr/local/lib/python3.8/dist-packages/tascaty_project/&gt;
                &lt;Files wsgi.py&gt;
                        Require all granted
                &lt;/Files&gt;
        &lt;/Directory&gt;

        Alias /tascaty/static /usr/local/lib/python3.8/dist-packages/static
        &lt;Directory /usr/local/lib/python3.8/dist-packages/static&gt;
                Require all granted
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</code></pre>
<p>Also, you need to remove this from the ingress manifest:</p>
<pre class="lang-yaml prettyprint-override"><code>    nginx.ingress.kubernetes.io/rewrite-target: /
</code></pre>
<p>✌️</p>
